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

Commit b189a4d5 authored by Zekan Qian's avatar Zekan Qian
Browse files

Change SpaEnvironmentFactory interface.

Allow user reset the environment multiple times in tests.

Test: manual - build Gallery
Change-Id: I5279698034667cf870c22d2194bba16096c3c56f
parent 1c2241d9
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -22,6 +22,6 @@ import com.android.settingslib.spa.framework.common.SpaEnvironmentFactory
class GalleryApplication : Application() {
class GalleryApplication : Application() {
    override fun onCreate() {
    override fun onCreate() {
        super.onCreate()
        super.onCreate()
        SpaEnvironmentFactory.instance = GallerySpaEnvironment
        SpaEnvironmentFactory.reset(GallerySpaEnvironment)
    }
    }
}
}
 No newline at end of file
+6 −8
Original line number Original line Diff line number Diff line
@@ -24,19 +24,17 @@ private const val TAG = "SpaEnvironment"
object SpaEnvironmentFactory {
object SpaEnvironmentFactory {
    private var spaEnvironment: SpaEnvironment? = null
    private var spaEnvironment: SpaEnvironment? = null


    var instance: SpaEnvironment
    fun reset(env: SpaEnvironment) {
        spaEnvironment = env
        Log.d(TAG, "reset")
    }

    val instance: SpaEnvironment
        get() {
        get() {
            if (spaEnvironment == null)
            if (spaEnvironment == null)
                throw UnsupportedOperationException("Spa environment is not set")
                throw UnsupportedOperationException("Spa environment is not set")
            return spaEnvironment!!
            return spaEnvironment!!
        }
        }
        set(env: SpaEnvironment) {
            if (spaEnvironment != null) {
                Log.w(TAG, "Spa environment is already set, ignore the latter one.")
                return
            }
            spaEnvironment = env
        }
}
}


abstract class SpaEnvironment {
abstract class SpaEnvironment {