diff options
-rw-r--r-- | apexd/apex_database.cpp | 12 | ||||
-rw-r--r-- | apexd/apex_file.cpp | 24 | ||||
-rw-r--r-- | apexd/apex_manifest.cpp | 2 | ||||
-rw-r--r-- | apexd/apex_preinstalled_data.cpp | 8 | ||||
-rw-r--r-- | apexd/apex_shim.cpp | 6 | ||||
-rw-r--r-- | apexd/apexd.cpp | 205 | ||||
-rw-r--r-- | apexd/apexd_loop.cpp | 4 | ||||
-rw-r--r-- | apexd/apexd_main.cpp | 2 | ||||
-rw-r--r-- | apexd/apexd_prepostinstall.cpp | 10 | ||||
-rw-r--r-- | apexd/apexd_prop.cpp | 6 | ||||
-rw-r--r-- | apexd/apexd_session.cpp | 10 | ||||
-rw-r--r-- | apexd/apexd_utils.h | 6 | ||||
-rw-r--r-- | apexd/apexd_verity.cpp | 9 | ||||
-rw-r--r-- | apexd/apexservice.cpp | 30 | ||||
-rw-r--r-- | libs/libapexutil/apexutil.cpp | 4 |
15 files changed, 170 insertions, 168 deletions
diff --git a/apexd/apex_database.cpp b/apexd/apex_database.cpp index 712c5f1..f8549a1 100644 --- a/apexd/apex_database.cpp +++ b/apexd/apex_database.cpp @@ -92,7 +92,7 @@ class BlockDevice { slaves.push_back(dev); } }); - if (!status) { + if (!status.ok()) { LOG(WARNING) << status.error(); } return slaves; @@ -138,7 +138,7 @@ Result<void> PopulateLoopInfo(const BlockDevice& top_device, return Error() << dev.DevPath() << " is not a loop device"; } auto backing_file = dev.GetProperty("loop/backing_file"); - if (!backing_file) { + if (!backing_file.ok()) { return backing_file.error(); } backing_files.push_back(std::move(*backing_file)); @@ -174,7 +174,7 @@ Result<MountedApexData> resolveMountInfo(const BlockDevice& block, switch (block.GetType()) { case LoopDevice: { auto backingFile = block.GetProperty("loop/backing_file"); - if (!backingFile) { + if (!backingFile.ok()) { return backingFile.error(); } return MountedApexData(block.DevPath(), *backingFile, mountPoint, @@ -183,13 +183,13 @@ Result<MountedApexData> resolveMountInfo(const BlockDevice& block, } case DeviceMapperDevice: { auto name = block.GetProperty("dm/name"); - if (!name) { + if (!name.ok()) { return name.error(); } MountedApexData result; result.mount_point = mountPoint; result.device_name = *name; - if (auto status = PopulateLoopInfo(block, &result); !status) { + if (auto status = PopulateLoopInfo(block, &result); !status.ok()) { return status.error(); } return result; @@ -241,7 +241,7 @@ void MountedApexDatabase::PopulateFromMounts() { } auto mountData = resolveMountInfo(BlockDevice(block), mountPoint); - if (!mountData) { + if (!mountData.ok()) { LOG(WARNING) << "Can't resolve mount info " << mountData.error(); continue; } diff --git a/apexd/apex_file.cpp b/apexd/apex_file.cpp index 49bd83b..b780d97 100644 --- a/apexd/apex_file.cpp +++ b/apexd/apex_file.cpp @@ -128,7 +128,7 @@ Result<ApexFile> ApexFile::Open(const std::string& path) { } else { manifest = ParseManifest(manifest_content); } - if (!manifest) { + if (!manifest.ok()) { return manifest.error(); } @@ -245,12 +245,12 @@ Result<void> verifyVbMetaSignature(const ApexFile& apex, const uint8_t* data, } Result<std::string> key_name = getPublicKeyName(apex, data, length); - if (!key_name) { + if (!key_name.ok()) { return key_name.error(); } Result<const std::string> public_key = getApexKey(*key_name); - if (public_key) { + if (public_key.ok()) { // TODO(b/115718846) // We need to decide whether we need rollback protection, and whether // we can use the rollback protection provided by libavb. @@ -290,7 +290,7 @@ Result<std::unique_ptr<uint8_t[]>> verifyVbMeta(const ApexFile& apex, Result<void> st = verifyVbMetaSignature(apex, vbmeta_buf.get(), footer.vbmeta_size); - if (!st) { + if (!st.ok()) { return st.error(); } @@ -349,25 +349,25 @@ Result<ApexVerityData> ApexFile::VerifyApexVerity() const { } Result<std::unique_ptr<AvbFooter>> footer = getAvbFooter(*this, fd); - if (!footer) { + if (!footer.ok()) { return footer.error(); } Result<std::unique_ptr<uint8_t[]>> vbmeta_data = verifyVbMeta(*this, fd, **footer); - if (!vbmeta_data) { + if (!vbmeta_data.ok()) { return vbmeta_data.error(); } Result<const AvbHashtreeDescriptor*> descriptor = findDescriptor(vbmeta_data->get(), (*footer)->vbmeta_size); - if (!descriptor) { + if (!descriptor.ok()) { return descriptor.error(); } Result<std::unique_ptr<AvbHashtreeDescriptor>> verifiedDescriptor = verifyDescriptor(*descriptor); - if (!verifiedDescriptor) { + if (!verifiedDescriptor.ok()) { return verifiedDescriptor.error(); } verityData.desc = std::move(*verifiedDescriptor); @@ -387,13 +387,13 @@ Result<void> ApexFile::VerifyManifestMatches( const std::string& mount_path) const { Result<ApexManifest> verifiedManifest = ReadManifest(mount_path + "/" + kManifestFilenamePb); - if (!verifiedManifest) { + if (!verifiedManifest.ok()) { LOG(ERROR) << "Could not read manifest from " << mount_path << "/" << kManifestFilenamePb << " : " << verifiedManifest.error(); // Fallback to Json manifest if present. LOG(ERROR) << "Trying to find a JSON manifest"; verifiedManifest = ReadManifest(mount_path + "/" + kManifestFilenameJson); - if (!verifiedManifest) { + if (!verifiedManifest.ok()) { return verifiedManifest.error(); } } @@ -411,13 +411,13 @@ Result<std::vector<std::string>> FindApexes( std::vector<std::string> result; for (const auto& path : paths) { auto exist = PathExists(path); - if (!exist) { + if (!exist.ok()) { return exist.error(); } if (!*exist) continue; const auto& apexes = FindApexFilesByName(path); - if (!apexes) { + if (!apexes.ok()) { return apexes; } diff --git a/apexd/apex_manifest.cpp b/apexd/apex_manifest.cpp index 76b484b..af3bfb8 100644 --- a/apexd/apex_manifest.cpp +++ b/apexd/apex_manifest.cpp @@ -52,7 +52,7 @@ Result<ApexManifest> ParseManifestJson(const std::string& content) { ApexManifest apex_manifest; Result<void> parse_manifest_status = JsonToApexManifestMessage(content, &apex_manifest); - if (!parse_manifest_status) { + if (!parse_manifest_status.ok()) { return parse_manifest_status.error(); } diff --git a/apexd/apex_preinstalled_data.cpp b/apexd/apex_preinstalled_data.cpp index 22c7e09..aeaec64 100644 --- a/apexd/apex_preinstalled_data.cpp +++ b/apexd/apex_preinstalled_data.cpp @@ -58,13 +58,13 @@ Result<std::vector<ApexPreinstalledData>> collectPreinstalleDataFromDir( return Error() << "Can't scan preinstalled APEX data from " << dir; } Result<std::vector<std::string>> apex_files = FindApexFilesByName(dir); - if (!apex_files) { + if (!apex_files.ok()) { return apex_files.error(); } for (const auto& file : *apex_files) { Result<ApexFile> apex_file = ApexFile::Open(file); - if (!apex_file) { + if (!apex_file.ok()) { return Error() << "Failed to open " << file << " : " << apex_file.error(); } ApexPreinstalledData apexPreInstalledData; @@ -100,12 +100,12 @@ Result<void> collectPreinstalledData(const std::vector<std::string>& dirs) { for (const auto& dir : dirs) { Result<std::vector<ApexPreinstalledData>> preinstalledData = collectPreinstalleDataFromDir(dir); - if (!preinstalledData) { + if (!preinstalledData.ok()) { return Error() << "Failed to collect keys from " << dir << " : " << preinstalledData.error(); } Result<void> st = updatePreinstalledData(*preinstalledData); - if (!st) { + if (!st.ok()) { return st; } } diff --git a/apexd/apex_shim.cpp b/apexd/apex_shim.cpp index f8b9756..ea58a32 100644 --- a/apexd/apex_shim.cpp +++ b/apexd/apex_shim.cpp @@ -95,7 +95,7 @@ Result<std::vector<std::string>> GetAllowedHashes(const std::string& path) { std::vector<std::string> allowed_hashes = android::base::Split(hash, "\n"); auto system_shim_hash = CalculateSha512( StringPrintf("%s/%s", kApexPackageSystemDir, shim::kSystemShimApexName)); - if (!system_shim_hash) { + if (!system_shim_hash.ok()) { return system_shim_hash.error(); } allowed_hashes.push_back(std::move(*system_shim_hash)); @@ -167,11 +167,11 @@ Result<void> ValidateUpdate(const std::string& system_apex_path, LOG(DEBUG) << "Validating update of shim apex to " << new_apex_path << " using system shim apex " << system_apex_path; auto allowed = GetAllowedHashes(system_apex_path); - if (!allowed) { + if (!allowed.ok()) { return allowed.error(); } auto actual = CalculateSha512(new_apex_path); - if (!actual) { + if (!actual.ok()) { return actual.error(); } auto it = std::find(allowed->begin(), allowed->end(), *actual); diff --git a/apexd/apexd.cpp b/apexd/apexd.cpp index 7405e29..9729b55 100644 --- a/apexd/apexd.cpp +++ b/apexd/apexd.cpp @@ -144,14 +144,14 @@ bool isBootstrapApex(const ApexFile& apex) { // later when actually activating APEXes. Result<void> preAllocateLoopDevices() { auto scan = FindApexes(kApexPackageBuiltinDirs); - if (!scan) { + if (!scan.ok()) { return scan.error(); } auto size = 0; for (const auto& path : *scan) { auto apexFile = ApexFile::Open(path); - if (!apexFile) { + if (!apexFile.ok()) { continue; } size++; @@ -238,7 +238,7 @@ class DmVerityDevice { ~DmVerityDevice() { if (!cleared_) { Result<void> ret = DeleteVerityDevice(name_); - if (!ret) { + if (!ret.ok()) { LOG(ERROR) << ret.error(); } } @@ -262,11 +262,11 @@ Result<DmVerityDevice> createVerityDevice(const std::string& name, if (dm.GetState(name) != DmDeviceState::INVALID) { // TODO: since apexd tears down devices during unmount, can this happen? LOG(WARNING) << "Deleting existing dm device " << name; - const Result<void>& status = DeleteVerityDevice(name); - if (!status) { + const Result<void>& result = DeleteVerityDevice(name); + if (!result.ok()) { // TODO: should we fail instead? LOG(ERROR) << "Failed to delete device " << name << " : " - << status.error(); + << result.error(); } } @@ -282,13 +282,13 @@ Result<void> RemovePreviouslyActiveApexFiles( const std::unordered_set<std::string>& files_to_keep) { auto all_active_apex_files = FindApexFilesByName(kActiveApexPackagesDataDir); - if (!all_active_apex_files) { + if (!all_active_apex_files.ok()) { return all_active_apex_files.error(); } for (const std::string& path : *all_active_apex_files) { Result<ApexFile> apex_file = ApexFile::Open(path); - if (!apex_file) { + if (!apex_file.ok()) { return apex_file.error(); } @@ -339,9 +339,9 @@ Result<void> readVerityDevice(const std::string& verity_device, Result<void> VerifyMountedImage(const ApexFile& apex, const std::string& mount_point) { - auto status = apex.VerifyManifestMatches(mount_point); - if (!status) { - return status; + auto result = apex.VerifyManifestMatches(mount_point); + if (!result.ok()) { + return result; } if (shim::IsShimApex(apex)) { return shim::ValidateShimApex(mount_point, apex); @@ -364,7 +364,7 @@ Result<MountedApexData> MountPackageImpl(const ApexFile& apex, // finds an empty directory under /apex, it's not a problem and apexd can use // it. auto exists = PathExists(mountPoint); - if (!exists) { + if (!exists.ok()) { return exists.error(); } if (!*exists && mkdir(mountPoint.c_str(), kMkdirMode) != 0) { @@ -386,7 +386,7 @@ Result<MountedApexData> MountPackageImpl(const ApexFile& apex, for (size_t attempts = 1;; ++attempts) { Result<loop::LoopbackDeviceUniqueFd> ret = loop::createLoopDevice( full_path, apex.GetImageOffset(), apex.GetImageSize()); - if (ret) { + if (ret.ok()) { loopbackDevice = std::move(*ret); break; } @@ -398,7 +398,7 @@ Result<MountedApexData> MountPackageImpl(const ApexFile& apex, LOG(VERBOSE) << "Loopback device created: " << loopbackDevice.name; auto verityData = apex.VerifyApexVerity(); - if (!verityData) { + if (!verityData.ok()) { return Error() << "Failed to verify Apex Verity data for " << full_path << ": " << verityData.error(); } @@ -417,11 +417,12 @@ Result<MountedApexData> MountPackageImpl(const ApexFile& apex, if (mountOnVerity) { std::string hash_device = loopbackDevice.name; if (verityData->desc->tree_size == 0) { - if (auto st = PrepareHashTree(apex, *verityData, hashtree_file); !st) { + if (auto st = PrepareHashTree(apex, *verityData, hashtree_file); + !st.ok()) { return st.error(); } auto create_loop_status = loop::createLoopDevice(hashtree_file, 0, 0); - if (!create_loop_status) { + if (!create_loop_status.ok()) { return create_loop_status.error(); } loop_for_hash = std::move(*create_loop_status); @@ -433,7 +434,7 @@ Result<MountedApexData> MountPackageImpl(const ApexFile& apex, /* restart_on_corruption = */ !verifyImage); Result<DmVerityDevice> verityDevRes = createVerityDevice(device_name, *verityTable); - if (!verityDevRes) { + if (!verityDevRes.ok()) { return Error() << "Failed to create Apex Verity device " << full_path << ": " << verityDevRes.error(); } @@ -443,7 +444,7 @@ Result<MountedApexData> MountPackageImpl(const ApexFile& apex, Result<void> readAheadStatus = loop::configureReadAhead(verityDev.GetDevPath()); - if (!readAheadStatus) { + if (!readAheadStatus.ok()) { return readAheadStatus.error(); } } @@ -451,7 +452,7 @@ Result<MountedApexData> MountPackageImpl(const ApexFile& apex, if (mountOnVerity && verifyImage) { Result<void> verityStatus = readVerityDevice(blockDevice, (*verityData).desc->image_size); - if (!verityStatus) { + if (!verityStatus.ok()) { return verityStatus.error(); } } @@ -466,7 +467,7 @@ Result<MountedApexData> MountPackageImpl(const ApexFile& apex, LOG(INFO) << "Successfully mounted package " << full_path << " on " << mountPoint; auto status = VerifyMountedImage(apex, mountPoint); - if (!status) { + if (!status.ok()) { if (umount2(mountPoint.c_str(), UMOUNT_NOFOLLOW) != 0) { PLOG(ERROR) << "Failed to umount " << mountPoint; } @@ -524,9 +525,9 @@ Result<void> Unmount(const MountedApexData& data) { // Try to free up the device-mapper device. if (!data.device_name.empty()) { - const auto& status = DeleteVerityDevice(data.device_name); - if (!status) { - return status; + const auto& result = DeleteVerityDevice(data.device_name); + if (!result.ok()) { + return result; } } @@ -555,17 +556,17 @@ Result<void> RunVerifyFnInsideTempMount(const ApexFile& apex, Result<MountedApexData> mount_status = VerifyAndTempMountPackage(apex, temp_mount_point); - if (!mount_status) { + if (!mount_status.ok()) { LOG(ERROR) << "Failed to temp mount to " << temp_mount_point << " : " << mount_status.error(); return mount_status.error(); } auto cleaner = [&]() { LOG(DEBUG) << "Unmounting " << temp_mount_point; - Result<void> status = Unmount(*mount_status); - if (!status) { + Result<void> result = Unmount(*mount_status); + if (!result.ok()) { LOG(WARNING) << "Failed to unmount " << temp_mount_point << " : " - << status.error(); + << result.error(); } }; auto scope_guard = android::base::make_scope_guard(cleaner); @@ -591,7 +592,7 @@ Result<void> PrePostinstallPackages(const std::vector<ApexFile>& apexes, // 2) If we found hooks, run the pre/post-install. if (has_hooks) { Result<void> install_status = (*call)(apexes); - if (!install_status) { + if (!install_status.ok()) { return install_status; } } @@ -615,7 +616,7 @@ RetType HandlePackages(const std::vector<std::string>& paths, Fn fn) { std::vector<ApexFile> apex_files; for (const std::string& path : paths) { Result<ApexFile> apex_file = ApexFile::Open(path); - if (!apex_file) { + if (!apex_file.ok()) { return apex_file.error(); } apex_files.emplace_back(std::move(*apex_file)); @@ -629,7 +630,7 @@ Result<void> ValidateStagingShimApex(const ApexFile& to) { using android::base::StringPrintf; auto system_shim = ApexFile::Open( StringPrintf("%s/%s", kApexPackageSystemDir, shim::kSystemShimApexName)); - if (!system_shim) { + if (!system_shim.ok()) { return system_shim.error(); } auto verify_fn = [&](const std::string& system_apex_path) { @@ -643,7 +644,7 @@ Result<void> ValidateStagingShimApex(const ApexFile& to) { // each boot. Try to avoid putting expensive checks inside this function. Result<void> VerifyPackageBoot(const ApexFile& apex_file) { Result<ApexVerityData> verity_or = apex_file.VerifyApexVerity(); - if (!verity_or) { + if (!verity_or.ok()) { return verity_or.error(); } @@ -651,9 +652,9 @@ Result<void> VerifyPackageBoot(const ApexFile& apex_file) { // Validating shim is not a very cheap operation, but it's fine to perform // it here since it only runs during CTS tests and will never be triggered // during normal flow. - const auto& status = ValidateStagingShimApex(apex_file); - if (!status) { - return status; + const auto& result = ValidateStagingShimApex(apex_file); + if (!result.ok()) { + return result; } } return {}; @@ -665,7 +666,7 @@ Result<void> VerifyPackageBoot(const ApexFile& apex_file) { // during boot. Result<void> VerifyPackageInstall(const ApexFile& apex_file) { const auto& verify_package_boot_status = VerifyPackageBoot(apex_file); - if (!verify_package_boot_status) { + if (!verify_package_boot_status.ok()) { return verify_package_boot_status; } Result<ApexVerityData> verity_or = apex_file.VerifyApexVerity(); @@ -686,9 +687,9 @@ Result<std::vector<ApexFile>> verifyPackages( auto verify_fn = [&](std::vector<ApexFile>& apexes) { for (const ApexFile& apex_file : apexes) { - Result<void> status = verify_apex_fn(apex_file); - if (!status) { - return Result<std::vector<ApexFile>>(status.error()); + Result<void> result = verify_apex_fn(apex_file); + if (!result.ok()) { + return Result<std::vector<ApexFile>>(result.error()); } } return Result<std::vector<ApexFile>>(std::move(apexes)); @@ -702,7 +703,7 @@ Result<ApexFile> verifySessionDir(const int session_id) { LOG(INFO) << "Scanning " << sessionDirPath << " looking for packages to be validated"; Result<std::vector<std::string>> scan = FindApexFilesByName(sessionDirPath); - if (!scan) { + if (!scan.ok()) { LOG(WARNING) << scan.error(); return scan.error(); } @@ -713,7 +714,7 @@ Result<ApexFile> verifySessionDir(const int session_id) { } auto verified = verifyPackages(*scan, VerifyPackageInstall); - if (!verified) { + if (!verified.ok()) { return verified.error(); } return std::move((*verified)[0]); @@ -721,7 +722,7 @@ Result<ApexFile> verifySessionDir(const int session_id) { Result<void> DeleteBackup() { auto exists = PathExists(std::string(kApexBackupDir)); - if (!exists) { + if (!exists.ok()) { return Error() << "Can't clean " << kApexBackupDir << " : " << exists.error(); } @@ -737,12 +738,12 @@ Result<void> BackupActivePackages() { // Previous restore might've delete backups folder. auto create_status = createDirIfNeeded(kApexBackupDir, 0700); - if (!create_status) { + if (!create_status.ok()) { return Error() << "Backup failed : " << create_status.error(); } auto apex_active_exists = PathExists(std::string(kActiveApexPackagesDataDir)); - if (!apex_active_exists) { + if (!apex_active_exists.ok()) { return Error() << "Backup failed : " << apex_active_exists.error(); } if (!*apex_active_exists) { @@ -752,12 +753,12 @@ Result<void> BackupActivePackages() { } auto active_packages = FindApexFilesByName(kActiveApexPackagesDataDir); - if (!active_packages) { + if (!active_packages.ok()) { return Error() << "Backup failed : " << active_packages.error(); } auto cleanup_status = DeleteBackup(); - if (!cleanup_status) { + if (!cleanup_status.ok()) { return Error() << "Backup failed : " << cleanup_status.error(); } @@ -768,17 +769,17 @@ Result<void> BackupActivePackages() { }; auto deleter = []() { - auto status = DeleteDirContent(std::string(kApexBackupDir)); - if (!status) { + auto result = DeleteDirContent(std::string(kApexBackupDir)); + if (!result.ok()) { LOG(ERROR) << "Failed to cleanup " << kApexBackupDir << " : " - << status.error(); + << result.error(); } }; auto scope_guard = android::base::make_scope_guard(deleter); for (const std::string& path : *active_packages) { Result<ApexFile> apex_file = ApexFile::Open(path); - if (!apex_file) { + if (!apex_file.ok()) { return Error() << "Backup failed : " << apex_file.error(); } const auto& dest_path = backup_path_fn(*apex_file); @@ -795,7 +796,7 @@ Result<void> RestoreActivePackages() { LOG(DEBUG) << "Initializing restore of " << kActiveApexPackagesDataDir; auto backup_exists = PathExists(std::string(kApexBackupDir)); - if (!backup_exists) { + if (!backup_exists.ok()) { return backup_exists.error(); } if (!*backup_exists) { @@ -810,7 +811,7 @@ Result<void> RestoreActivePackages() { LOG(DEBUG) << "Deleting existing packages in " << kActiveApexPackagesDataDir; auto delete_status = DeleteDirContent(std::string(kActiveApexPackagesDataDir)); - if (!delete_status) { + if (!delete_status.ok()) { return delete_status; } @@ -879,7 +880,7 @@ Result<void> MountPackage(const ApexFile& apex, const std::string& mountPoint) { MountPackageImpl(apex, mountPoint, GetPackageId(apex.GetManifest()), GetHashTreeFileName(apex, /* is_new = */ false), /* verifyImage = */ false); - if (!ret) { + if (!ret.ok()) { return ret.error(); } @@ -954,7 +955,7 @@ Result<void> activatePackageImpl(const ApexFile& apex_file) { gMountedApexes.ForallMountedApexes( manifest.name(), [&](const MountedApexData& data, bool latest) { Result<ApexFile> otherApex = ApexFile::Open(data.full_path); - if (!otherApex) { + if (!otherApex.ok()) { return; } found_other_version = true; @@ -979,7 +980,7 @@ Result<void> activatePackageImpl(const ApexFile& apex_file) { if (!version_found_mounted) { auto mountStatus = MountPackage(apex_file, mountPoint); - if (!mountStatus) { + if (!mountStatus.ok()) { return mountStatus; } } @@ -989,7 +990,7 @@ Result<void> activatePackageImpl(const ApexFile& apex_file) { const Result<void>& update_st = apexd_private::BindMount( apexd_private::GetActiveMountPoint(manifest), mountPoint); mounted_latest = update_st.has_value(); - if (!update_st) { + if (!update_st.ok()) { return Error() << "Failed to update package " << manifest.name() << " to version " << manifest.version() << " : " << update_st.error(); @@ -1009,7 +1010,7 @@ Result<void> activatePackage(const std::string& full_path) { LOG(INFO) << "Trying to activate " << full_path; Result<ApexFile> apex_file = ApexFile::Open(full_path); - if (!apex_file) { + if (!apex_file.ok()) { return apex_file.error(); } return activatePackageImpl(*apex_file); @@ -1019,7 +1020,7 @@ Result<void> deactivatePackage(const std::string& full_path) { LOG(INFO) << "Trying to deactivate " << full_path; Result<ApexFile> apexFile = ApexFile::Open(full_path); - if (!apexFile) { + if (!apexFile.ok()) { return apexFile.error(); } @@ -1035,7 +1036,7 @@ std::vector<ApexFile> getActivePackages() { } Result<ApexFile> apexFile = ApexFile::Open(data.full_path); - if (!apexFile) { + if (!apexFile.ok()) { // TODO: Fail? return; } @@ -1062,13 +1063,13 @@ std::vector<ApexFile> getFactoryPackages() { std::vector<ApexFile> ret; for (const auto& dir : kApexPackageBuiltinDirs) { auto apex_files = FindApexFilesByName(dir); - if (!apex_files) { + if (!apex_files.ok()) { LOG(ERROR) << apex_files.error(); continue; } for (const std::string& path : *apex_files) { Result<ApexFile> apex_file = ApexFile::Open(path); - if (!apex_file) { + if (!apex_file.ok()) { LOG(ERROR) << apex_file.error(); } else { ret.emplace_back(std::move(*apex_file)); @@ -1096,7 +1097,7 @@ Result<ApexFile> getActivePackage(const std::string& packageName) { **/ Result<void> abortStagedSession(int session_id) { auto session = ApexSession::GetSession(session_id); - if (!session) { + if (!session.ok()) { return Error() << "No session found with id " << session_id; } switch (session->GetState()) { @@ -1116,7 +1117,7 @@ Result<void> scanPackagesDirAndActivate(const char* apex_package_dir) { return {}; } Result<std::vector<std::string>> scan = FindApexFilesByName(apex_package_dir); - if (!scan) { + if (!scan.ok()) { return Error() << "Failed to scan " << apex_package_dir << " : " << scan.error(); } @@ -1130,7 +1131,7 @@ Result<void> scanPackagesDirAndActivate(const char* apex_package_dir) { LOG(INFO) << "Found " << name; Result<ApexFile> apex_file = ApexFile::Open(name); - if (!apex_file) { + if (!apex_file.ok()) { LOG(ERROR) << "Failed to activate " << name << " : " << apex_file.error(); failed_pkgs.push_back(name); continue; @@ -1148,7 +1149,7 @@ Result<void> scanPackagesDirAndActivate(const char* apex_package_dir) { } Result<void> res = activatePackageImpl(*apex_file); - if (!res) { + if (!res.ok()) { LOG(ERROR) << "Failed to activate " << name << " : " << res.error(); failed_pkgs.push_back(name); } else { @@ -1178,7 +1179,7 @@ Result<void> snapshotDataDirectory(const std::string& base_dir, StringPrintf("%s/%s/%d%s", base_dir.c_str(), kApexSnapshotSubDir, rollback_id, pre_restore ? kPreRestoreSuffix : ""); const Result<void> result = createDirIfNeeded(rollback_path, 0700); - if (!result) { + if (!result.ok()) { return Error() << "Failed to create snapshot directory for rollback " << rollback_id << " : " << result.error(); } @@ -1230,7 +1231,7 @@ void snapshotOrRestoreDeIfNeeded(const std::string& base_dir, } Result<void> result = restoreDataDirectory(base_dir, session.GetRollbackId(), apex_name); - if (!result) { + if (!result.ok()) { LOG(ERROR) << "Restore of data failed for " << apex_name << ": " << result.error(); } @@ -1408,7 +1409,7 @@ void scanStagedSessionsDirAndStage() { auto session_failed_fn = [&]() { LOG(WARNING) << "Marking session " << sessionId << " as failed."; auto st = session.UpdateStateAndCommit(SessionState::ACTIVATION_FAILED); - if (!st) { + if (!st.ok()) { LOG(WARNING) << "Failed to mark session " << sessionId << " as failed : " << st.error(); } @@ -1436,7 +1437,7 @@ void scanStagedSessionsDirAndStage() { bool scanSuccessful = true; for (const auto& dirToScan : dirsToScan) { Result<std::vector<std::string>> scan = FindApexFilesByName(dirToScan); - if (!scan) { + if (!scan.ok()) { LOG(WARNING) << scan.error(); scanSuccessful = false; break; @@ -1464,7 +1465,7 @@ void scanStagedSessionsDirAndStage() { // Run postinstall, if necessary. Result<void> postinstall_status = postinstallPackages(apexes); - if (!postinstall_status) { + if (!postinstall_status.ok()) { LOG(ERROR) << "Postinstall failed for session " << std::to_string(sessionId) << ": " << postinstall_status.error(); @@ -1482,7 +1483,7 @@ void scanStagedSessionsDirAndStage() { } const Result<void> result = stagePackages(apexes); - if (!result) { + if (!result.ok()) { LOG(ERROR) << "Activation failed for packages " << Join(apexes, ',') << ": " << result.error(); continue; @@ -1492,7 +1493,7 @@ void scanStagedSessionsDirAndStage() { scope_guard.Disable(); auto st = session.UpdateStateAndCommit(SessionState::ACTIVATED); - if (!st) { + if (!st.ok()) { LOG(ERROR) << "Failed to mark " << session << " as activated : " << st.error(); } @@ -1535,14 +1536,14 @@ Result<void> stagePackages(const std::vector<std::string>& tmpPaths) { // 1) Verify all packages. auto verify_status = verifyPackages(tmpPaths, VerifyPackageBoot); - if (!verify_status) { + if (!verify_status.ok()) { return verify_status.error(); } // Make sure that kActiveApexPackagesDataDir exists. auto create_dir_status = createDirIfNeeded(std::string(kActiveApexPackagesDataDir), 0750); - if (!create_dir_status) { + if (!create_dir_status.ok()) { return create_dir_status.error(); } @@ -1568,7 +1569,7 @@ Result<void> stagePackages(const std::vector<std::string>& tmpPaths) { std::unordered_set<std::string> staged_packages; for (const std::string& path : tmpPaths) { Result<ApexFile> apex_file = ApexFile::Open(path); - if (!apex_file) { + if (!apex_file.ok()) { return apex_file.error(); } // First promote new hashtree file to the one that will be used when @@ -1668,7 +1669,7 @@ Result<void> revertActiveSessions(const std::string& crashing_native_process) { if (!gInFsCheckpointMode) { auto restoreStatus = RestoreActivePackages(); - if (!restoreStatus) { + if (!restoreStatus.ok()) { for (auto& session : activeSessions) { auto st = session.UpdateStateAndCommit(SessionState::REVERT_FAILED); LOG(DEBUG) << "Marking " << session << " as failed to revert"; @@ -1703,14 +1704,14 @@ Result<void> revertActiveSessions(const std::string& crashing_native_process) { Result<void> revertActiveSessionsAndReboot( const std::string& crashing_native_process) { auto status = revertActiveSessions(crashing_native_process); - if (!status) { + if (!status.ok()) { return status; } LOG(ERROR) << "Successfully reverted. Time to reboot device."; if (gInFsCheckpointMode) { Result<void> res = gVoldService->AbortChanges( "apexd_initiated" /* message */, false /* retry */); - if (!res) { + if (!res.ok()) { LOG(ERROR) << res.error(); } } @@ -1722,7 +1723,7 @@ int onBootstrap() { gBootstrap = true; Result<void> preAllocate = preAllocateLoopDevices(); - if (!preAllocate) { + if (!preAllocate.ok()) { LOG(ERROR) << "Failed to pre-allocate loop devices : " << preAllocate.error(); } @@ -1730,7 +1731,7 @@ int onBootstrap() { std::vector<std::string> bootstrap_apex_dirs{ kApexPackageSystemDir, kApexPackageSystemExtDir, kApexPackageVendorDir}; Result<void> status = collectPreinstalledData(bootstrap_apex_dirs); - if (!status) { + if (!status.ok()) { LOG(ERROR) << "Failed to collect APEX keys : " << status.error(); return 1; } @@ -1738,7 +1739,7 @@ int onBootstrap() { // Activate built-in APEXes for processes launched before /data is mounted. for (auto const& dir : bootstrap_apex_dirs) { status = scanPackagesDirAndActivate(dir.c_str()); - if (!status) { + if (!status.ok()) { LOG(ERROR) << "Failed to activate APEX files in " << dir << " : " << status.error(); return 1; @@ -1750,10 +1751,10 @@ int onBootstrap() { Result<void> remountApexFile(const std::string& path) { auto ret = deactivatePackage(path); - if (!ret) return ret.error(); + if (!ret.ok()) return ret.error(); ret = activatePackage(path); - if (!ret) return ret.error(); + if (!ret.ok()) return ret.error(); return {}; } @@ -1793,7 +1794,7 @@ Result<void> monitorBuiltinDirs() { } else { std::string path = desc_to_dir.at(e->wd) + "/" + e->name; auto ret = remountApexFile(path); - if (!ret) { + if (!ret.ok()) { LOG(ERROR) << ret.error().message(); } else { LOG(INFO) << path << " remounted because it was changed"; @@ -1819,7 +1820,7 @@ void onStart(CheckpointInterface* checkpoint_service) { gVoldService = checkpoint_service; Result<bool> supports_fs_checkpoints = gVoldService->SupportsFsCheckpoints(); - if (supports_fs_checkpoints) { + if (supports_fs_checkpoints.ok()) { gSupportsFsCheckpoints = *supports_fs_checkpoints; } else { LOG(ERROR) << "Failed to check if filesystem checkpoints are supported: " @@ -1827,7 +1828,7 @@ void onStart(CheckpointInterface* checkpoint_service) { } if (gSupportsFsCheckpoints) { Result<bool> needs_checkpoint = gVoldService->NeedsCheckpoint(); - if (needs_checkpoint) { + if (needs_checkpoint.ok()) { gInFsCheckpointMode = *needs_checkpoint; } else { LOG(ERROR) << "Failed to check if we're in filesystem checkpoint mode: " @@ -1841,7 +1842,7 @@ void onStart(CheckpointInterface* checkpoint_service) { // checkpointing. if (gSupportsFsCheckpoints) { Result<bool> needs_revert = gVoldService->NeedsRollback(); - if (!needs_revert) { + if (!needs_revert.ok()) { LOG(ERROR) << "Failed to check if we need a revert: " << needs_revert.error(); } else if (*needs_revert) { @@ -1853,7 +1854,7 @@ void onStart(CheckpointInterface* checkpoint_service) { } Result<void> status = collectPreinstalledData(kApexPackageBuiltinDirs); - if (!status) { + if (!status.ok()) { LOG(ERROR) << "Failed to collect APEX keys : " << status.error(); return; } @@ -1864,16 +1865,16 @@ void onStart(CheckpointInterface* checkpoint_service) { // system one, the new one will eclipse the old one. scanStagedSessionsDirAndStage(); status = resumeRevertIfNeeded(); - if (!status) { + if (!status.ok()) { LOG(ERROR) << "Failed to resume revert : " << status.error(); } status = scanPackagesDirAndActivate(kActiveApexPackagesDataDir); - if (!status) { + if (!status.ok()) { LOG(ERROR) << "Failed to activate packages from " << kActiveApexPackagesDataDir << " : " << status.error(); Result<void> revert_status = revertActiveSessionsAndReboot(""); - if (!revert_status) { + if (!revert_status.ok()) { // TODO: should we kill apexd in this case? LOG(ERROR) << "Failed to revert : " << revert_status.error(); } @@ -1882,7 +1883,7 @@ void onStart(CheckpointInterface* checkpoint_service) { for (const auto& dir : kApexPackageBuiltinDirs) { // TODO(b/123622800): if activation failed, revert and reboot. status = scanPackagesDirAndActivate(dir.c_str()); - if (!status) { + if (!status.ok()) { // This should never happen. Like **really** never. // TODO: should we kill apexd in this case? LOG(ERROR) << "Failed to activate packages from " << dir << " : " @@ -1895,7 +1896,7 @@ void onStart(CheckpointInterface* checkpoint_service) { if (android::base::GetBoolProperty("ro.debuggable", false)) { status = monitorBuiltinDirs(); - if (!status) { + if (!status.ok()) { LOG(ERROR) << "cannot monitor built-in dirs: " << status.error(); } } @@ -1925,7 +1926,7 @@ Result<std::vector<ApexFile>> submitStagedSession( if (!gSupportsFsCheckpoints) { Result<void> backup_status = BackupActivePackages(); - if (!backup_status) { + if (!backup_status.ok()) { // Do not proceed with staged install without backup return backup_status.error(); } @@ -1941,7 +1942,7 @@ Result<std::vector<ApexFile>> submitStagedSession( std::vector<ApexFile> ret; for (int id_to_scan : ids_to_scan) { auto verified = verifySessionDir(id_to_scan); - if (!verified) { + if (!verified.ok()) { return verified.error(); } ret.push_back(std::move(*verified)); @@ -1949,7 +1950,7 @@ Result<std::vector<ApexFile>> submitStagedSession( // Run preinstall, if necessary. Result<void> preinstall_status = PreinstallPackages(ret); - if (!preinstall_status) { + if (!preinstall_status.ok()) { return preinstall_status.error(); } @@ -1959,7 +1960,7 @@ Result<std::vector<ApexFile>> submitStagedSession( } auto session = ApexSession::CreateSession(session_id); - if (!session) { + if (!session.ok()) { return session.error(); } (*session).SetChildSessionIds(child_session_ids); @@ -1970,7 +1971,7 @@ Result<std::vector<ApexFile>> submitStagedSession( session->SetRollbackId(rollback_id); Result<void> commit_status = (*session).UpdateStateAndCommit(SessionState::VERIFIED); - if (!commit_status) { + if (!commit_status.ok()) { return commit_status.error(); } @@ -1979,7 +1980,7 @@ Result<std::vector<ApexFile>> submitStagedSession( Result<void> markStagedSessionReady(const int session_id) { auto session = ApexSession::GetSession(session_id); - if (!session) { + if (!session.ok()) { return session.error(); } // We should only accept sessions in SessionState::VERIFIED or @@ -1998,7 +1999,7 @@ Result<void> markStagedSessionReady(const int session_id) { Result<void> markStagedSessionSuccessful(const int session_id) { auto session = ApexSession::GetSession(session_id); - if (!session) { + if (!session.ok()) { return session.error(); } // Only SessionState::ACTIVATED or SessionState::SUCCESS states are accepted. @@ -2007,7 +2008,7 @@ Result<void> markStagedSessionSuccessful(const int session_id) { return {}; } else if (session->GetState() == SessionState::ACTIVATED) { auto cleanup_status = DeleteBackup(); - if (!cleanup_status) { + if (!cleanup_status.ok()) { return Error() << "Failed to mark session " << *session << " as successful : " << cleanup_status.error(); } @@ -2036,7 +2037,7 @@ void unmountDanglingMounts() { const std::string& path = data.full_path; LOG(VERBOSE) << "Unmounting " << data.mount_point; gMountedApexes.RemoveMountedApex(package, path); - if (auto st = Unmount(data); !st) { + if (auto st = Unmount(data); !st.ok()) { LOG(ERROR) << st.error(); } if (StartsWith(path, kActiveApexPackagesDataDir)) { @@ -2067,7 +2068,7 @@ int unmountAll() { ret = 1; } } - if (auto status = Unmount(data); !status) { + if (auto status = Unmount(data); !status.ok()) { LOG(ERROR) << "Failed to unmount " << data.mount_point << " : " << status.error(); ret = 1; diff --git a/apexd/apexd_loop.cpp b/apexd/apexd_loop.cpp index a086d69..568eb05 100644 --- a/apexd/apexd_loop.cpp +++ b/apexd/apexd_loop.cpp @@ -92,7 +92,7 @@ Result<void> configureReadAhead(const std::string& device_path) { Result<void> preAllocateLoopDevices(size_t num) { Result<void> loopReady = WaitForFile("/dev/loop-control", 20s); - if (!loopReady) { + if (!loopReady.ok()) { return loopReady; } unique_fd ctl_fd( @@ -215,7 +215,7 @@ Result<LoopbackDeviceUniqueFd> createLoopDevice(const std::string& target, } Result<void> readAheadStatus = configureReadAhead(device); - if (!readAheadStatus) { + if (!readAheadStatus.ok()) { return readAheadStatus.error(); } return device_fd; diff --git a/apexd/apexd_main.cpp b/apexd/apexd_main.cpp index 50c05e1..28680df 100644 --- a/apexd/apexd_main.cpp +++ b/apexd/apexd_main.cpp @@ -86,7 +86,7 @@ int main(int /*argc*/, char** argv) { android::base::Result<android::apex::VoldCheckpointInterface> vold_service_st = android::apex::VoldCheckpointInterface::Create(); android::apex::VoldCheckpointInterface* vold_service = nullptr; - if (!vold_service_st) { + if (!vold_service_st.ok()) { LOG(ERROR) << "Could not retrieve vold service: " << vold_service_st.error(); } else { diff --git a/apexd/apexd_prepostinstall.cpp b/apexd/apexd_prepostinstall.cpp index 0f162ff..21b8650 100644 --- a/apexd/apexd_prepostinstall.cpp +++ b/apexd/apexd_prepostinstall.cpp @@ -83,7 +83,7 @@ Result<void> StageFnInstall(const std::vector<ApexFile>& apexes, Fn fn, auto preinstall_guard = android::base::make_scope_guard([&]() { for (const auto& mount : mounted_apexes) { Result<void> st = apexd_private::Unmount(mount); - if (!st) { + if (!st.ok()) { LOG(ERROR) << "Failed to unmount " << mount.full_path << " from " << mount.mount_point << " after " << name << ": " << st.error(); @@ -103,7 +103,7 @@ Result<void> StageFnInstall(const std::vector<ApexFile>& apexes, Fn fn, apexd_private::GetPackageTempMountPoint(apex.GetManifest()); auto mount_data = apexd_private::TempMountPackage(apex, mount_point); - if (!mount_data) { + if (!mount_data.ok()) { return mount_data.error(); } mounted_apexes.push_back(std::move(*mount_data)); @@ -166,14 +166,14 @@ int RunFnInstall(char** in_argv, Fn fn, const char* name) { { Result<ApexManifest> manifest_or = ReadManifest(mount_point + "/" + kManifestFilenamePb); - if (!manifest_or) { + if (!manifest_or.ok()) { LOG(ERROR) << "Could not read manifest from " << mount_point << "/" << kManifestFilenamePb << " for " << name << ": " << manifest_or.error(); // Fallback to Json manifest if present. LOG(ERROR) << "Trying to find a JSON manifest"; manifest_or = ReadManifest(mount_point + "/" + kManifestFilenameJson); - if (!manifest_or) { + if (!manifest_or.ok()) { LOG(ERROR) << "Could not read manifest from " << mount_point << "/" << kManifestFilenameJson << " for " << name << ": " << manifest_or.error(); @@ -188,7 +188,7 @@ int RunFnInstall(char** in_argv, Fn fn, const char* name) { // 3) Activate the new apex. Result<void> bind_status = apexd_private::BindMount(active_point, mount_point); - if (!bind_status) { + if (!bind_status.ok()) { LOG(ERROR) << "Failed to bind-mount " << mount_point << " to " << active_point << ": " << bind_status.error(); _exit(203); diff --git a/apexd/apexd_prop.cpp b/apexd/apexd_prop.cpp index 295d6d4..e702c96 100644 --- a/apexd/apexd_prop.cpp +++ b/apexd/apexd_prop.cpp @@ -43,9 +43,9 @@ void waitForBootStatus(Result<void> (&revert_fn)(const std::string&), auto name = GetProperty("sys.init.updatable_crashing_process_name", ""); LOG(ERROR) << "Native process '" << (name.empty() ? "[unknown]" : name) << "' is crashing. Attempting a revert"; - auto status = revert_fn(name); - if (!status) { - LOG(ERROR) << "Revert failed : " << status.error(); + auto result = revert_fn(name); + if (!result.ok()) { + LOG(ERROR) << "Revert failed : " << result.error(); } else { LOG(INFO) << "Successfuly reverted update. Rebooting device"; Reboot(); diff --git a/apexd/apexd_session.cpp b/apexd/apexd_session.cpp index 507bb2f..8120803 100644 --- a/apexd/apexd_session.cpp +++ b/apexd/apexd_session.cpp @@ -52,13 +52,13 @@ std::string getSessionStateFilePath(int session_id) { Result<std::string> createSessionDirIfNeeded(int session_id) { // create /data/sessions auto res = createDirIfNeeded(kApexSessionsDir, 0700); - if (!res) { + if (!res.ok()) { return res.error(); } // create /data/sessions/session_id std::string sessionDir = getSessionDir(session_id); res = createDirIfNeeded(sessionDir, 0700); - if (!res) { + if (!res.ok()) { return res.error(); } @@ -86,7 +86,7 @@ Result<ApexSession> ApexSession::CreateSession(int session_id) { SessionState state; // Create session directory auto sessionPath = createSessionDirIfNeeded(session_id); - if (!sessionPath) { + if (!sessionPath.ok()) { return sessionPath.error(); } state.set_id(session_id); @@ -122,14 +122,14 @@ std::vector<ApexSession> ApexSession::GetSessions() { return entry.is_directory(ec); }); - if (!sessionPaths) { + if (!sessionPaths.ok()) { return sessions; } for (const std::string& sessionDirPath : *sessionPaths) { // Try to read session state auto session = GetSessionFromFile(sessionDirPath + "/" + kStateFileName); - if (!session) { + if (!session.ok()) { LOG(WARNING) << session.error(); continue; } diff --git a/apexd/apexd_utils.h b/apexd/apexd_utils.h index 47dc151..33df0af 100644 --- a/apexd/apexd_utils.h +++ b/apexd/apexd_utils.h @@ -118,7 +118,7 @@ Result<std::vector<std::string>> ReadDir(const std::string& path, FilterFn fn) { ret.push_back(entry.path()); } }); - if (!status) { + if (!status.ok()) { return status.error(); } return ret; @@ -126,7 +126,7 @@ Result<std::vector<std::string>> ReadDir(const std::string& path, FilterFn fn) { inline bool IsEmptyDirectory(const std::string& path) { auto res = ReadDir(path, [](auto _) { return true; }); - return res && res->empty(); + return res.ok() && res->empty(); } inline Result<void> createDirIfNeeded(const std::string& path, mode_t mode) { @@ -157,7 +157,7 @@ inline Result<void> createDirIfNeeded(const std::string& path, mode_t mode) { inline Result<void> DeleteDirContent(const std::string& path) { auto files = ReadDir(path, [](auto _) { return true; }); - if (!files) { + if (!files.ok()) { return Error() << "Failed to delete " << path << " : " << files.error(); } for (const std::string& file : *files) { diff --git a/apexd/apexd_verity.cpp b/apexd/apexd_verity.cpp index f0dce45..a4be336 100644 --- a/apexd/apexd_verity.cpp +++ b/apexd/apexd_verity.cpp @@ -149,17 +149,17 @@ Result<std::string> CalculateRootDigest(const std::string& hashtree_file, Result<PrepareHashTreeResult> PrepareHashTree( const ApexFile& apex, const ApexVerityData& verity_data, const std::string& hashtree_file) { - if (auto st = createDirIfNeeded(kApexHashTreeDir, 0700); !st) { + if (auto st = createDirIfNeeded(kApexHashTreeDir, 0700); !st.ok()) { return st.error(); } bool should_regenerate_hashtree = false; auto exists = PathExists(hashtree_file); - if (!exists) { + if (!exists.ok()) { return exists.error(); } if (*exists) { auto digest = CalculateRootDigest(hashtree_file, verity_data); - if (!digest) { + if (!digest.ok()) { return digest.error(); } if (*digest != verity_data.root_digest) { @@ -174,7 +174,8 @@ Result<PrepareHashTreeResult> PrepareHashTree( } if (should_regenerate_hashtree) { - if (auto st = GenerateHashTree(apex, verity_data, hashtree_file); !st) { + if (auto st = GenerateHashTree(apex, verity_data, hashtree_file); + !st.ok()) { return st.error(); } LOG(INFO) << "hashtree: generated to " << hashtree_file; diff --git a/apexd/apexservice.cpp b/apexd/apexservice.cpp index 78a9620..4e95f66 100644 --- a/apexd/apexservice.cpp +++ b/apexd/apexservice.cpp @@ -114,7 +114,7 @@ BinderStatus ApexService::stagePackages(const std::vector<std::string>& paths) { Result<void> res = ::android::apex::stagePackages(paths); - if (res) { + if (res.ok()) { return BinderStatus::ok(); } @@ -129,7 +129,7 @@ BinderStatus ApexService::stagePackages(const std::vector<std::string>& paths) { BinderStatus ApexService::unstagePackages( const std::vector<std::string>& paths) { Result<void> res = ::android::apex::unstagePackages(paths); - if (res) { + if (res.ok()) { return BinderStatus::ok(); } @@ -150,7 +150,7 @@ BinderStatus ApexService::submitStagedSession(const ApexSessionParams& params, Result<std::vector<ApexFile>> packages = ::android::apex::submitStagedSession( params.sessionId, params.childSessionIds, params.hasRollbackEnabled, params.isRollback, params.rollbackId); - if (!packages) { + if (!packages.ok()) { LOG(ERROR) << "Failed to submit session id " << params.sessionId << ": " << packages.error(); return BinderStatus::fromExceptionCode( @@ -172,7 +172,7 @@ BinderStatus ApexService::markStagedSessionReady(int session_id) { LOG(DEBUG) << "markStagedSessionReady() received by ApexService, session id " << session_id; Result<void> success = ::android::apex::markStagedSessionReady(session_id); - if (!success) { + if (!success.ok()) { LOG(ERROR) << "Failed to mark session id " << session_id << " as ready: " << success.error(); return BinderStatus::fromExceptionCode( @@ -187,7 +187,7 @@ BinderStatus ApexService::markStagedSessionSuccessful(int session_id) { << "markStagedSessionSuccessful() received by ApexService, session id " << session_id; Result<void> ret = ::android::apex::markStagedSessionSuccessful(session_id); - if (!ret) { + if (!ret.ok()) { LOG(ERROR) << "Failed to mark session " << session_id << " as SUCCESS: " << ret.error(); return BinderStatus::fromExceptionCode( @@ -260,7 +260,7 @@ static ApexInfo getApexInfo(const ApexFile& package) { out.isActive = false; Result<std::string> preinstalledPath = getApexPreinstalledPath(package.GetManifest().name()); - if (preinstalledPath) { + if (preinstalledPath.ok()) { out.preinstalledModulePath = *preinstalledPath; } return out; @@ -295,7 +295,7 @@ BinderStatus ApexService::getStagedSessionInfo( LOG(DEBUG) << "getStagedSessionInfo() received by ApexService, session id " << session_id; auto session = ApexSession::GetSession(session_id); - if (!session) { + if (!session.ok()) { // Unknown session. ClearSessionInfo(apex_session_info); apex_session_info->isUnknown = true; @@ -318,7 +318,7 @@ BinderStatus ApexService::activatePackage(const std::string& packagePath) { Result<void> res = ::android::apex::activatePackage(packagePath); - if (res) { + if (res.ok()) { return BinderStatus::ok(); } @@ -340,7 +340,7 @@ BinderStatus ApexService::deactivatePackage(const std::string& packagePath) { Result<void> res = ::android::apex::deactivatePackage(packagePath); - if (res) { + if (res.ok()) { return BinderStatus::ok(); } @@ -366,7 +366,7 @@ BinderStatus ApexService::getActivePackages( BinderStatus ApexService::getActivePackage(const std::string& packageName, ApexInfo* aidl_return) { Result<ApexFile> apex = ::android::apex::getActivePackage(packageName); - if (apex) { + if (apex.ok()) { *aidl_return = getApexInfo(*apex); aidl_return->isActive = true; } @@ -400,7 +400,7 @@ BinderStatus ApexService::preinstallPackages( } Result<void> res = ::android::apex::preinstallPackages(paths); - if (res) { + if (res.ok()) { return BinderStatus::ok(); } @@ -420,7 +420,7 @@ BinderStatus ApexService::postinstallPackages( } Result<void> res = ::android::apex::postinstallPackages(paths); - if (res) { + if (res.ok()) { return BinderStatus::ok(); } @@ -435,7 +435,7 @@ BinderStatus ApexService::postinstallPackages( BinderStatus ApexService::abortStagedSession(int session_id) { LOG(DEBUG) << "abortStagedSession() received by ApexService."; Result<void> res = ::android::apex::abortStagedSession(session_id); - if (!res) { + if (!res.ok()) { return BinderStatus::fromExceptionCode( BinderStatus::EX_ILLEGAL_ARGUMENT, String8(res.error().message().c_str())); @@ -446,7 +446,7 @@ BinderStatus ApexService::abortStagedSession(int session_id) { BinderStatus ApexService::revertActiveSessions() { LOG(DEBUG) << "revertActiveSessions() received by ApexService."; Result<void> res = ::android::apex::revertActiveSessions(""); - if (!res) { + if (!res.ok()) { return BinderStatus::fromExceptionCode( BinderStatus::EX_ILLEGAL_ARGUMENT, String8(res.error().message().c_str())); @@ -462,7 +462,7 @@ BinderStatus ApexService::resumeRevertIfNeeded() { LOG(DEBUG) << "resumeRevertIfNeeded() received by ApexService."; Result<void> res = ::android::apex::resumeRevertIfNeeded(); - if (!res) { + if (!res.ok()) { return BinderStatus::fromExceptionCode( BinderStatus::EX_ILLEGAL_ARGUMENT, String8(res.error().message().c_str())); diff --git a/libs/libapexutil/apexutil.cpp b/libs/libapexutil/apexutil.cpp index 948bd86..e0b0787 100644 --- a/libs/libapexutil/apexutil.cpp +++ b/libs/libapexutil/apexutil.cpp @@ -69,7 +69,7 @@ GetActivePackages(const std::string &apex_root) { continue; std::string apex_path = apex_root + "/" + entry->d_name; auto manifest = ParseApexManifest(apex_path + "/apex_manifest.pb"); - if (manifest) { + if (manifest.ok()) { apexes.emplace(std::move(apex_path), std::move(*manifest)); } else { LOG(WARNING) << manifest.error(); @@ -79,4 +79,4 @@ GetActivePackages(const std::string &apex_root) { } } // namespace apex -} // namespace android
\ No newline at end of file +} // namespace android |