Change SpaEnvironmentFactory interface.
Allow user reset the environment multiple times in tests. Test: manual - build Gallery Change-Id: I5279698034667cf870c22d2194bba16096c3c56f
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user