summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-04-28 16:05:29 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-04-28 16:05:29 +0000
commit96dbdb6cd5de441abee94345d8df516f53e3a2ae (patch)
tree78cadbb95d8ecf7a181d8934e05dc1185ea606b4
parent7117da69dfe1be9cec5a6d7b19fe0aa757b36c48 (diff)
parent1f83bd3f4e0fdd6fc4dbe7a41f0052ae29598bf6 (diff)
downloadgsid-android13-frc-cellbroadcast-release.tar.gz
Snap for 8512216 from 1f83bd3f4e0fdd6fc4dbe7a41f0052ae29598bf6 to tm-frc-cellbroadcast-releaset_frc_cbr_330443000android13-frc-cellbroadcast-release
Change-Id: I240724a0dfcb9d8379c6f7b8fbe10f6c3b73960f
-rw-r--r--aidl/android/gsi/IGsiService.aidl6
-rw-r--r--aidl/android/gsi/IImageService.aidl5
-rw-r--r--gsi_service.cpp83
-rw-r--r--gsi_service.h2
4 files changed, 53 insertions, 43 deletions
diff --git a/aidl/android/gsi/IGsiService.aidl b/aidl/android/gsi/IGsiService.aidl
index c889987..3b5d6c0 100644
--- a/aidl/android/gsi/IGsiService.aidl
+++ b/aidl/android/gsi/IGsiService.aidl
@@ -74,8 +74,10 @@ interface IGsiService {
boolean commitGsiChunkFromAshmem(long bytes);
/**
- * Complete a GSI installation and mark it as bootable. The caller is
- * responsible for rebooting the device as soon as possible.
+ * Mark a completed DSU installation as bootable. The caller is responsible
+ * for rebooting the device as soon as possible.
+ *
+ * Could leave the installation in "disabled" state if failure.
*
* @param oneShot If true, the GSI will boot once and then disable itself.
* It can still be re-enabled again later with setGsiBootable.
diff --git a/aidl/android/gsi/IImageService.aidl b/aidl/android/gsi/IImageService.aidl
index c8c5a9d..363a919 100644
--- a/aidl/android/gsi/IImageService.aidl
+++ b/aidl/android/gsi/IImageService.aidl
@@ -135,6 +135,11 @@ interface IImageService {
void removeDisabledImages();
/**
+ * Return whether an image is disabled.
+ */
+ boolean isImageDisabled(@utf8InCpp String name);
+
+ /**
* Return the block device path of a mapped image, or an empty string if not mapped.
*/
@utf8InCpp String getMappedImageDevice(@utf8InCpp String name);
diff --git a/gsi_service.cpp b/gsi_service.cpp
index c7b3a28..3392a1d 100644
--- a/gsi_service.cpp
+++ b/gsi_service.cpp
@@ -314,12 +314,10 @@ binder::Status GsiService::setGsiAshmem(const ::android::os::ParcelFileDescripto
binder::Status GsiService::enableGsiAsync(bool one_shot, const std::string& dsuSlot,
const sp<IGsiServiceCallback>& resultCallback) {
- int result;
- auto status = enableGsi(one_shot, dsuSlot, &result);
- if (!status.isOk()) {
- LOG(ERROR) << "Could not enableGsi: " << status.exceptionMessage().string();
- result = IGsiService::INSTALL_ERROR_GENERIC;
- }
+ ENFORCE_SYSTEM_OR_SHELL;
+ std::lock_guard<std::mutex> guard(lock_);
+
+ const auto result = EnableGsi(one_shot, dsuSlot);
resultCallback->onResult(result);
return binder::Status::ok();
}
@@ -328,20 +326,7 @@ binder::Status GsiService::enableGsi(bool one_shot, const std::string& dsuSlot,
ENFORCE_SYSTEM_OR_SHELL;
std::lock_guard<std::mutex> guard(lock_);
- if (!WriteStringToFile(dsuSlot, kDsuActiveFile)) {
- PLOG(ERROR) << "write failed: " << GetDsuSlot(install_dir_);
- *_aidl_return = INSTALL_ERROR_GENERIC;
- return binder::Status::ok();
- }
- RestoreconMetadataFiles();
-
- if (installer_) {
- LOG(ERROR) << "cannot enable an ongoing installation, was closeInstall() called?";
- *_aidl_return = IGsiService::INSTALL_ERROR_GENERIC;
- return binder::Status::ok();
- }
-
- *_aidl_return = ReenableGsi(one_shot);
+ *_aidl_return = EnableGsi(one_shot, dsuSlot);
return binder::Status::ok();
}
@@ -594,6 +579,7 @@ class ImageService : public BinderService<ImageService>, public BnImageService {
binder::Status removeAllImages() override;
binder::Status removeDisabledImages() override;
binder::Status getMappedImageDevice(const std::string& name, std::string* device) override;
+ binder::Status isImageDisabled(const std::string& name, bool* _aidl_return) override;
private:
bool CheckUid();
@@ -764,6 +750,14 @@ binder::Status ImageService::removeDisabledImages() {
return binder::Status::ok();
}
+binder::Status ImageService::isImageDisabled(const std::string& name, bool* _aidl_return) {
+ if (!CheckUid()) return UidSecurityError();
+
+ std::lock_guard<std::mutex> guard(service_->lock());
+ *_aidl_return = impl_->IsImageDisabled(name);
+ return binder::Status::ok();
+}
+
binder::Status ImageService::getMappedImageDevice(const std::string& name, std::string* device) {
if (!CheckUid()) return UidSecurityError();
@@ -937,26 +931,6 @@ std::string GsiService::GetInstalledImageDir() {
return kDefaultDsuImageFolder;
}
-int GsiService::ReenableGsi(bool one_shot) {
- if (!android::gsi::IsGsiInstalled()) {
- LOG(ERROR) << "no gsi installed - cannot re-enable";
- return INSTALL_ERROR_GENERIC;
- }
- std::string boot_key;
- if (!GetInstallStatus(&boot_key)) {
- PLOG(ERROR) << "read " << kDsuInstallStatusFile;
- return INSTALL_ERROR_GENERIC;
- }
- if (boot_key != kInstallStatusDisabled) {
- LOG(ERROR) << "GSI is not currently disabled";
- return INSTALL_ERROR_GENERIC;
- }
- if (!SetBootMode(one_shot) || !ResetBootAttemptCounter()) {
- return IGsiService::INSTALL_ERROR_GENERIC;
- }
- return IGsiService::INSTALL_OK;
-}
-
static android::sp<android::os::IVold> GetVoldService() {
return android::waitForService<android::os::IVold>(android::String16("vold"));
}
@@ -1012,6 +986,35 @@ bool GsiService::RemoveGsiFiles(const std::string& install_dir) {
return ok;
}
+int GsiService::EnableGsi(bool one_shot, const std::string& dsu_slot) {
+ if (!android::gsi::IsGsiInstalled()) {
+ LOG(ERROR) << "no gsi installed - cannot enable";
+ return IGsiService::INSTALL_ERROR_GENERIC;
+ }
+ if (installer_) {
+ LOG(ERROR) << "cannot enable an ongoing installation, was closeInstall() called?";
+ return IGsiService::INSTALL_ERROR_GENERIC;
+ }
+
+ if (!DisableGsi()) {
+ PLOG(ERROR) << "cannot write DSU status file";
+ return IGsiService::INSTALL_ERROR_GENERIC;
+ }
+ if (!SetBootMode(one_shot)) {
+ return IGsiService::INSTALL_ERROR_GENERIC;
+ }
+ if (!ResetBootAttemptCounter()) {
+ return IGsiService::INSTALL_ERROR_GENERIC;
+ }
+
+ if (!WriteStringToFile(dsu_slot, kDsuActiveFile)) {
+ PLOG(ERROR) << "cannot write active DSU slot (" << dsu_slot << "): " << kDsuActiveFile;
+ return IGsiService::INSTALL_ERROR_GENERIC;
+ }
+ RestoreconMetadataFiles();
+ return IGsiService::INSTALL_OK;
+}
+
bool GsiService::DisableGsiInstall() {
if (!android::gsi::IsGsiInstalled()) {
LOG(ERROR) << "cannot disable gsi install - no install detected";
diff --git a/gsi_service.h b/gsi_service.h
index 0ec7620..c50c101 100644
--- a/gsi_service.h
+++ b/gsi_service.h
@@ -92,8 +92,8 @@ class GsiService : public BinderService<GsiService>, public BnGsiService {
GsiService();
static int ValidateInstallParams(std::string& install_dir);
+ int EnableGsi(bool one_shot, const std::string& dsu_slot);
bool DisableGsiInstall();
- int ReenableGsi(bool one_shot);
static void CleanCorruptedInstallation();
static int SaveInstallation(const std::string&);
static bool IsInstallationComplete(const std::string&);