Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8e650d38 authored by Soichiro Fujii's avatar Soichiro Fujii
Browse files

libprefetch: check `ro.prefetch_boot.enabled` internally

Checking this value on the prefetch internally prevents
it from starting unless you explicitly enable the feature.

Bug: 380766679
Test: Builds
Test: Build emulator image with `ro.prefetch_boot.enabled 0`.
observe prefetch record exiting even when other condition meets.

Change-Id: Iadce8bd77a6b5299f33efdf5e195e715798f5104
parent 31da755b
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -12,6 +12,12 @@ use rustutils::system_properties::PropertyWatcher;

const PREFETCH_RECORD_PROPERTY_STOP: &str = "prefetch_boot.record_stop";

fn is_prefetch_enabled() -> Result<bool, Error> {
    rustutils::system_properties::read_bool("ro.prefetch_boot.enabled", false).map_err(|e| {
        Error::Custom { error: format!("Failed to read ro.prefetch_boot.enabled: {}", e) }
    })
}

fn wait_for_property_true(
    property_name: &str,
    timeout: Option<Duration>,
@@ -31,6 +37,10 @@ pub fn wait_for_record_stop() {
/// Checks if we can perform replay phase.
/// Ensure that the pack file exists and is up-to-date, returns false otherwise.
pub fn can_perform_replay(pack_path: &Path, fingerprint_path: &Path) -> Result<bool, Error> {
    if !is_prefetch_enabled()? {
        return Ok(false);
    }

    if !pack_path.exists() || !fingerprint_path.exists() {
        return Ok(false);
    }
@@ -54,6 +64,10 @@ pub fn ensure_record_is_ready(
    pack_path: &Path,
    fingerprint_path: &Path,
) -> Result<bool, Error> {
    if !is_prefetch_enabled()? {
        return Ok(false);
    }

    if !ready_path.exists() {
        File::create(ready_path)
            .map_err(|_| Error::Custom { error: "File Creation failed".to_string() })?;