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

Commit f428b273 authored by Nate Myren's avatar Nate Myren
Browse files

Move DataRepository init below variable declaration

By calling registerComponentCallback before initializing the lock, there is a
very slight chance that the DataRepository will be asked to remove data
before the lock object has been instantiated

Fixes: 156568613
Test: tested simplified version with guarenteed execution
Change-Id: I55bafb2a4b00fd276cf6594e44d6f8130ee33ff7
parent ba810b1c
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -30,10 +30,6 @@ import java.util.concurrent.TimeUnit
 */
abstract class DataRepository<K, V : DataRepository.InactiveTimekeeper> : ComponentCallbacks2 {

    init {
        PermissionControllerApplication.get().registerComponentCallbacks(this)
    }

    /**
     * Deadlines for removal based on memory pressure. Live Data objects which have been inactive
     * for longer than the deadline will be removed.
@@ -42,9 +38,9 @@ abstract class DataRepository<K, V : DataRepository.InactiveTimekeeper> : Compon
    private val TIME_THRESHOLD_TIGHT_NANOS: Long = TimeUnit.NANOSECONDS.convert(1, TimeUnit.MINUTES)
    private val TIME_THRESHOLD_ALL_NANOS: Long = 0

    protected val lock = Any()
    @GuardedBy("lock")
    protected val data = mutableMapOf<K, V>()
    protected val lock = Any()

    /**
     * Whether or not this data repository has been registered as a component callback yet
@@ -56,6 +52,10 @@ abstract class DataRepository<K, V : DataRepository.InactiveTimekeeper> : Compon
    private var isLowMemoryDevice = PermissionControllerApplication.get().getSystemService(
        ActivityManager::class.java)?.isLowRamDevice ?: false

    init {
        PermissionControllerApplication.get().registerComponentCallbacks(this)
    }

    /**
     * Get a value from this repository, creating it if needed
     *