Change SpaEnvironmentFactory interface.

Allow user reset the environment multiple times in tests.

Test: manual - build Gallery
Change-Id: I5279698034667cf870c22d2194bba16096c3c56f
This commit is contained in:
Zekan Qian
2022-10-17 10:11:47 +08:00
parent 1c2241d939
commit b189a4d5e5
2 changed files with 7 additions and 9 deletions

View File

@@ -22,6 +22,6 @@ import com.android.settingslib.spa.framework.common.SpaEnvironmentFactory
class GalleryApplication : Application() {
override fun onCreate() {
super.onCreate()
SpaEnvironmentFactory.instance = GallerySpaEnvironment
SpaEnvironmentFactory.reset(GallerySpaEnvironment)
}
}

View File

@@ -24,19 +24,17 @@ private const val TAG = "SpaEnvironment"
object SpaEnvironmentFactory {
private var spaEnvironment: SpaEnvironment? = null
var instance: SpaEnvironment
fun reset(env: SpaEnvironment) {
spaEnvironment = env
Log.d(TAG, "reset")
}
val instance: SpaEnvironment
get() {
if (spaEnvironment == null)
throw UnsupportedOperationException("Spa environment is not set")
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 {