Allow pre-singleton types to be registered in RegistrationContext
Bug: 181070625
Test: m droid
Change-Id: I708b78ed0b42ec55b0442307f40531cfe1233c2b
diff --git a/android/register.go b/android/register.go
index 18c743f..47df972 100644
--- a/android/register.go
+++ b/android/register.go
@@ -168,6 +168,7 @@
type RegistrationContext interface {
RegisterModuleType(name string, factory ModuleFactory)
RegisterSingletonModuleType(name string, factory SingletonModuleFactory)
+ RegisterPreSingletonType(name string, factory SingletonFactory)
RegisterSingletonType(name string, factory SingletonFactory)
PreArchMutators(f RegisterMutatorFunc)
@@ -208,6 +209,7 @@
type initRegistrationContext struct {
moduleTypes map[string]ModuleFactory
singletonTypes map[string]SingletonFactory
+ preSingletonTypes map[string]SingletonFactory
moduleTypesForDocs map[string]reflect.Value
}
@@ -238,6 +240,14 @@
RegisterSingletonType(name, factory)
}
+func (ctx *initRegistrationContext) RegisterPreSingletonType(name string, factory SingletonFactory) {
+ if _, present := ctx.preSingletonTypes[name]; present {
+ panic(fmt.Sprintf("pre singleton type %q is already registered", name))
+ }
+ ctx.preSingletonTypes[name] = factory
+ RegisterPreSingletonType(name, factory)
+}
+
func (ctx *initRegistrationContext) PreArchMutators(f RegisterMutatorFunc) {
PreArchMutators(f)
}