summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGavin Corkery <gavincorkery@google.com>2020-09-28 16:33:16 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2020-09-28 16:33:16 +0000
commit45aadd9ff46a616b2647a48faccbb2edd87495b4 (patch)
treef2546a03591e2dc92d2600c15779a58a87807851
parenta5f9c449e47515ac3ae1dedece4559014fdf0ab7 (diff)
parent6a6b6654215becf967a8ea4742e09d4fe6d7ead4 (diff)
downloadplatform_system_apex-45aadd9ff46a616b2647a48faccbb2edd87495b4.tar.gz
platform_system_apex-45aadd9ff46a616b2647a48faccbb2edd87495b4.tar.bz2
platform_system_apex-45aadd9ff46a616b2647a48faccbb2edd87495b4.zip
Merge changes from topic "cp-markbootcompleted"
* changes: Refactor apexd boot logic to a new class Handle boot completed calls from ApexManager
-rw-r--r--apexd/Android.bp2
-rw-r--r--apexd/aidl/android/apex/IApexService.aidl5
-rw-r--r--apexd/apex_constants.h6
-rw-r--r--apexd/apexd.cpp18
-rw-r--r--apexd/apexd.h3
-rw-r--r--apexd/apexd_lifecycle.cpp (renamed from apexd/apexd_prop.cpp)29
-rw-r--r--apexd/apexd_lifecycle.h (renamed from apexd/apexd_prop.h)25
-rw-r--r--apexd/apexd_main.cpp10
-rw-r--r--apexd/apexservice.cpp6
9 files changed, 62 insertions, 42 deletions
diff --git a/apexd/Android.bp b/apexd/Android.bp
index e9e54706..a56d9cad 100644
--- a/apexd/Android.bp
+++ b/apexd/Android.bp
@@ -144,10 +144,10 @@ cc_library_static {
srcs: [
"apex_database.cpp",
"apexd.cpp",
+ "apexd_lifecycle.cpp",
"apexd_loop.cpp",
"apexd_prepostinstall.cpp",
"apexd_private.cpp",
- "apexd_prop.cpp",
"apexd_session.cpp",
"apexd_verity.cpp",
],
diff --git a/apexd/aidl/android/apex/IApexService.aidl b/apexd/aidl/android/apex/IApexService.aidl
index 23b4a1ff..4d9b5f73 100644
--- a/apexd/aidl/android/apex/IApexService.aidl
+++ b/apexd/aidl/android/apex/IApexService.aidl
@@ -122,4 +122,9 @@ interface IApexService {
* on user builds. Only root is allowed to call this method.
*/
void recollectPreinstalledData(in @utf8InCpp List<String> paths);
+
+ /**
+ * Informs apexd that the boot has completed.
+ */
+ oneway void markBootCompleted();
}
diff --git a/apexd/apex_constants.h b/apexd/apex_constants.h
index b9e91ced..2c3ea92b 100644
--- a/apexd/apex_constants.h
+++ b/apexd/apex_constants.h
@@ -52,5 +52,11 @@ static constexpr const char* kManifestFilenameJson = "apex_manifest.json";
static constexpr const char* kManifestFilenamePb = "apex_manifest.pb";
static constexpr const char* kApexInfoList = "apex-info-list.xml";
+
+// These should be in-sync with system/sepolicy/private/property_contexts
+static constexpr const char* kApexStatusSysprop = "apexd.status";
+static constexpr const char* kApexStatusStarting = "starting";
+static constexpr const char* kApexStatusActivated = "activated";
+static constexpr const char* kApexStatusReady = "ready";
} // namespace apex
} // namespace android
diff --git a/apexd/apexd.cpp b/apexd/apexd.cpp
index 7e9695ba..5d219874 100644
--- a/apexd/apexd.cpp
+++ b/apexd/apexd.cpp
@@ -24,9 +24,9 @@
#include "apex_preinstalled_data.h"
#include "apex_shim.h"
#include "apexd_checkpoint.h"
+#include "apexd_lifecycle.h"
#include "apexd_loop.h"
#include "apexd_prepostinstall.h"
-#include "apexd_prop.h"
#include "apexd_rollback_utils.h"
#include "apexd_session.h"
#include "apexd_utils.h"
@@ -101,12 +101,6 @@ using MountedApexData = MountedApexDatabase::MountedApexData;
namespace {
-// These should be in-sync with system/sepolicy/private/property_contexts
-static constexpr const char* kApexStatusSysprop = "apexd.status";
-static constexpr const char* kApexStatusStarting = "starting";
-static constexpr const char* kApexStatusActivated = "activated";
-static constexpr const char* kApexStatusReady = "ready";
-
static constexpr const char* kBuildFingerprintSysprop = "ro.build.fingerprint";
// This should be in UAPI, but it's not :-(
@@ -1624,6 +1618,11 @@ void deleteDePreRestoreSnapshots(const ApexSession& session) {
}
}
+void onBootCompleted() {
+ ApexdLifecycle::getInstance().markBootCompleted();
+ bootCompletedCleanup();
+}
+
void scanStagedSessionsDirAndStage() {
LOG(INFO) << "Scanning " << kApexSessionsDir
<< " looking for sessions to be activated.";
@@ -2361,11 +2360,6 @@ int unmountAll() {
return ret;
}
-bool isBooting() {
- auto status = GetProperty(kApexStatusSysprop, "");
- return status != kApexStatusReady && status != kApexStatusActivated;
-}
-
Result<void> remountPackages() {
std::vector<std::string> apexes;
gMountedApexes.ForallMountedApexes([&apexes](const std::string& /*package*/,
diff --git a/apexd/apexd.h b/apexd/apexd.h
index 2399b734..2d3080fa 100644
--- a/apexd/apexd.h
+++ b/apexd/apexd.h
@@ -87,8 +87,6 @@ android::base::Result<void> destroyCeSnapshotsNotSpecified(
int user_id, const std::vector<int>& retain_rollback_ids);
int onBootstrap();
-// Small helper function to tell if device is currently booting.
-bool isBooting();
// Sets the values of gVoldService and gInFsCheckpointMode.
void initializeVold(CheckpointInterface* checkpoint_service);
// Initializes in-memory state (e.g. pre-installed data, activated apexes).
@@ -112,6 +110,7 @@ void onAllPackagesActivated();
// Must only be called during boot (i.e. apexd.status is not "ready" or
// "activated").
void onAllPackagesReady();
+void onBootCompleted();
void bootCompletedCleanup();
int snapshotOrRestoreDeUserData();
diff --git a/apexd/apexd_prop.cpp b/apexd/apexd_lifecycle.cpp
index 067994c4..c44ca5ae 100644
--- a/apexd/apexd_prop.cpp
+++ b/apexd/apexd_lifecycle.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 The Android Open Source Project
+ * Copyright (C) 2020 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.
@@ -16,23 +16,28 @@
#define LOG_TAG "apexd"
-#include "apexd_prop.h"
+#include "apexd_lifecycle.h"
#include <android-base/logging.h>
#include <android-base/properties.h>
#include "apexd_utils.h"
-using android::base::GetBoolProperty;
using android::base::GetProperty;
using android::base::Result;
using android::base::WaitForProperty;
namespace android {
namespace apex {
-void waitForBootStatus(Result<void> (&revert_fn)(const std::string&),
- void (&complete_fn)()) {
- while (!GetBoolProperty("sys.boot_completed", false)) {
+
+bool ApexdLifecycle::isBooting() {
+ auto status = GetProperty(kApexStatusSysprop, "");
+ return status != kApexStatusReady && status != kApexStatusActivated;
+}
+
+void ApexdLifecycle::waitForBootStatus(
+ Result<void> (&revert_fn)(const std::string&)) {
+ while (!boot_completed_) {
// Check for change in either crashing property or sys.boot_completed
// Wait for updatable_crashing property change for most of the time
// (arbitrary 30s), briefly check if boot has completed successfully,
@@ -59,15 +64,9 @@ void waitForBootStatus(Result<void> (&revert_fn)(const std::string&),
}
}
}
- // Wait for boot to complete, and then run complete_fn.
- // TODO(b/158467962): this is a hack, instead we should have a binder call
- // from system_server into apexd when boot completes.
- if (WaitForProperty("sys.boot_completed", "1", std::chrono::minutes(5))) {
- complete_fn();
- return;
- } else {
- LOG(ERROR) << "Boot never completed";
- }
}
+
+void ApexdLifecycle::markBootCompleted() { boot_completed_ = true; }
+
} // namespace apex
} // namespace android
diff --git a/apexd/apexd_prop.h b/apexd/apexd_lifecycle.h
index 4b8a7661..bdd3863a 100644
--- a/apexd/apexd_prop.h
+++ b/apexd/apexd_lifecycle.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 The Android Open Source Project
+ * Copyright (C) 2020 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.
@@ -14,19 +14,30 @@
* limitations under the License.
*/
-#ifndef ANDROID_APEXD_APEXD_PROP_H_
-#define ANDROID_APEXD_APEXD_PROP_H_
+#ifndef ANDROID_APEXD_APEXD_LIFECYCLE_H_
+#define ANDROID_APEXD_APEXD_LIFECYCLE_H_
#include <android-base/result.h>
namespace android {
namespace apex {
-void waitForBootStatus(
- android::base::Result<void> (&rollback_fn)(const std::string&),
- void (&complete_fn)());
+class ApexdLifecycle {
+ private:
+ ApexdLifecycle(){};
+ std::atomic<bool> boot_completed_;
+ public:
+ static ApexdLifecycle& getInstance() {
+ static ApexdLifecycle instance;
+ return instance;
+ }
+ bool isBooting();
+ void markBootCompleted();
+ void waitForBootStatus(
+ android::base::Result<void> (&rollback_fn)(const std::string&));
+};
} // namespace apex
} // namespace android
-#endif // ANDROID_APEXD_APEXD_PROP_H
+#endif // ANDROID_APEXD_APEXD_LIFECYCLE_H \ No newline at end of file
diff --git a/apexd/apexd_main.cpp b/apexd/apexd_main.cpp
index b8d4f855..3b0a1399 100644
--- a/apexd/apexd_main.cpp
+++ b/apexd/apexd_main.cpp
@@ -24,13 +24,15 @@
#include "apexd.h"
#include "apexd_checkpoint_vold.h"
+#include "apexd_lifecycle.h"
#include "apexd_prepostinstall.h"
-#include "apexd_prop.h"
#include "apexservice.h"
#include <android-base/properties.h>
namespace {
+android::apex::ApexdLifecycle& lifecycle =
+ android::apex::ApexdLifecycle::getInstance();
int HandleSubcommand(char** argv) {
if (strcmp("--pre-install", argv[1]) == 0) {
@@ -137,7 +139,7 @@ int main(int /*argc*/, char** argv) {
}
android::apex::initialize(vold_service);
- bool booting = android::apex::isBooting();
+ bool booting = lifecycle.isBooting();
if (booting) {
android::apex::migrateSessionsDirIfNeeded();
android::apex::onStart();
@@ -153,9 +155,7 @@ int main(int /*argc*/, char** argv) {
// the "--snapshotde" subcommand is received and snapshot/restore is
// complete.
android::apex::onAllPackagesActivated();
- android::apex::waitForBootStatus(
- android::apex::revertActiveSessionsAndReboot,
- android::apex::bootCompletedCleanup);
+ lifecycle.waitForBootStatus(android::apex::revertActiveSessionsAndReboot);
}
android::apex::binder::AllowServiceShutdown();
diff --git a/apexd/apexservice.cpp b/apexd/apexservice.cpp
index c900bb79..d72db84a 100644
--- a/apexd/apexservice.cpp
+++ b/apexd/apexservice.cpp
@@ -103,6 +103,7 @@ class ApexService : public BnApexService {
BinderStatus remountPackages() override;
BinderStatus recollectPreinstalledData(
const std::vector<std::string>& paths) override;
+ BinderStatus markBootCompleted() override;
status_t dump(int fd, const Vector<String16>& args) override;
@@ -213,6 +214,11 @@ BinderStatus ApexService::markStagedSessionSuccessful(int session_id) {
return BinderStatus::ok();
}
+BinderStatus ApexService::markBootCompleted() {
+ ::android::apex::onBootCompleted();
+ return BinderStatus::ok();
+}
+
static void ClearSessionInfo(ApexSessionInfo* session_info) {
session_info->sessionId = -1;
session_info->isUnknown = false;