blob: fdf22f61e2604828e6b9ac6afe42336c90e975ee [file] [log] [blame]
Steven Morelandd56e5bb2017-07-18 22:04:16 -07001// Copyright (C) 2017 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package hidl
16
17import (
18 "strings"
Steven Morelandd56e5bb2017-07-18 22:04:16 -070019
Steven Moreland744eb322018-07-25 16:31:08 -070020 "github.com/google/blueprint"
Steven Morelandd56e5bb2017-07-18 22:04:16 -070021 "github.com/google/blueprint/proptools"
22
23 "android/soong/android"
24 "android/soong/cc"
25 "android/soong/genrule"
26 "android/soong/java"
27)
28
29var (
30 hidlInterfaceSuffix = "_interface"
Steven Moreland744eb322018-07-25 16:31:08 -070031
32 pctx = android.NewPackageContext("android/hidl")
33
34 hidl = pctx.HostBinToolVariable("hidl", "hidl-gen")
35 hidlRule = pctx.StaticRule("hidlRule", blueprint.RuleParams{
36 Depfile: "${depfile}",
37 Deps: blueprint.DepsGCC,
Steven Morelandbc98bdb2018-10-31 14:47:07 -070038 Command: "rm -rf ${genDir} && ${hidl} -R -p . -d ${depfile} -o ${genDir} -L ${language} ${roots} ${fqName}",
Steven Moreland744eb322018-07-25 16:31:08 -070039 CommandDeps: []string{"${hidl}"},
40 Description: "HIDL ${language}: ${in} => ${out}",
41 }, "depfile", "fqName", "genDir", "language", "roots")
Steven Morelandd56e5bb2017-07-18 22:04:16 -070042)
43
44func init() {
45 android.RegisterModuleType("hidl_interface", hidlInterfaceFactory)
46}
47
Steven Moreland744eb322018-07-25 16:31:08 -070048type hidlGenProperties struct {
49 Language string
50 FqName string
51 Interfaces []string
52 Inputs []string
53 Outputs []string
54}
55
56type hidlGenRule struct {
57 android.ModuleBase
58
59 properties hidlGenProperties
60
61 genOutputDir android.Path
62 genInputs android.Paths
63 genOutputs android.WritablePaths
64}
65
66var _ android.SourceFileProducer = (*hidlGenRule)(nil)
67var _ genrule.SourceFileGenerator = (*hidlGenRule)(nil)
68
69func (g *hidlGenRule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
70 g.genOutputDir = android.PathForModuleGen(ctx)
71
72 for _, input := range g.properties.Inputs {
73 g.genInputs = append(g.genInputs, android.PathForModuleSrc(ctx, input))
74 }
75
76 for _, output := range g.properties.Outputs {
77 g.genOutputs = append(g.genOutputs, android.PathForModuleGen(ctx, output))
78 }
79
80 var fullRootOptions []string
81 ctx.VisitDirectDeps(func(dep android.Module) {
82 fullRootOptions = append(fullRootOptions, dep.(*hidlInterface).properties.Full_root_option)
83 })
84
85 fullRootOptions = android.FirstUniqueStrings(fullRootOptions)
86
87 ctx.ModuleBuild(pctx, android.ModuleBuildParams{
88 Rule: hidlRule,
89 Inputs: g.genInputs,
90 Output: g.genOutputs[0],
91 ImplicitOutputs: g.genOutputs[1:],
92 Args: map[string]string{
93 "depfile": g.genOutputs[0].String() + ".d",
94 "genDir": g.genOutputDir.String(),
95 "fqName": g.properties.FqName,
96 "language": g.properties.Language,
97 "roots": strings.Join(fullRootOptions, " "),
98 },
99 })
100}
101
102func (g *hidlGenRule) GeneratedSourceFiles() android.Paths {
103 return g.genOutputs.Paths()
104}
105
106func (g *hidlGenRule) Srcs() android.Paths {
107 return g.genOutputs.Paths()
108}
109
110func (g *hidlGenRule) GeneratedDeps() android.Paths {
111 return g.genOutputs.Paths()
112}
113
114func (g *hidlGenRule) GeneratedHeaderDirs() android.Paths {
115 return android.Paths{g.genOutputDir}
116}
117
118func (g *hidlGenRule) DepsMutator(ctx android.BottomUpMutatorContext) {
119 ctx.AddDependency(ctx.Module(), nil, g.properties.FqName+hidlInterfaceSuffix)
120 ctx.AddDependency(ctx.Module(), nil, wrap("", g.properties.Interfaces, hidlInterfaceSuffix)...)
121}
122
123func hidlGenFactory() android.Module {
124 g := &hidlGenRule{}
125 g.AddProperties(&g.properties)
126 android.InitAndroidModule(g)
127 return g
128}
129
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700130type hidlInterfaceProperties struct {
131 // Vndk properties for interface library only.
132 cc.VndkProperties
133
Steven Moreland89a9ebb2017-12-04 10:18:00 -0800134 // The owner of the module
135 Owner *string
136
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700137 // List of .hal files which compose this interface.
138 Srcs []string
139
140 // List of hal interface packages that this library depends on.
141 Interfaces []string
142
143 // Package root for this package, must be a prefix of name
144 Root string
145
146 // List of non-TypeDef types declared in types.hal.
147 Types []string
148
149 // Whether to generate the Java library stubs.
150 // Default: true
151 Gen_java *bool
152
153 // Whether to generate a Java library containing constants
154 // expressed by @export annotations in the hal files.
155 Gen_java_constants bool
Steven Moreland744eb322018-07-25 16:31:08 -0700156
157 // example: -randroid.hardware:hardware/interfaces
158 Full_root_option string `blueprint:"mutated"`
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700159}
160
161type hidlInterface struct {
162 android.ModuleBase
163
164 properties hidlInterfaceProperties
165}
166
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700167func processSources(mctx android.LoadHookContext, srcs []string) ([]string, []string, bool) {
168 var interfaces []string
169 var types []string // hidl-gen only supports types.hal, but don't assume that here
170
171 hasError := false
172
173 for _, v := range srcs {
174 if !strings.HasSuffix(v, ".hal") {
175 mctx.PropertyErrorf("srcs", "Source must be a .hal file: "+v)
176 hasError = true
177 continue
178 }
179
180 name := strings.TrimSuffix(v, ".hal")
181
182 if strings.HasPrefix(name, "I") {
183 baseName := strings.TrimPrefix(name, "I")
184 interfaces = append(interfaces, baseName)
185 } else {
186 types = append(types, name)
187 }
188 }
189
190 return interfaces, types, !hasError
191}
192
193func processDependencies(mctx android.LoadHookContext, interfaces []string) ([]string, []string, bool) {
194 var dependencies []string
195 var javaDependencies []string
196
197 hasError := false
198
199 for _, v := range interfaces {
200 name, err := parseFqName(v)
201 if err != nil {
202 mctx.PropertyErrorf("interfaces", err.Error())
203 hasError = true
204 continue
205 }
206 dependencies = append(dependencies, name.string())
207 javaDependencies = append(javaDependencies, name.javaName())
208 }
209
210 return dependencies, javaDependencies, !hasError
211}
212
Steven Moreland744eb322018-07-25 16:31:08 -0700213func removeCoreDependencies(mctx android.LoadHookContext, dependencies []string) []string {
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700214 var ret []string
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700215
216 for _, i := range dependencies {
Steven Morelandb49d3a72018-07-25 16:40:03 -0700217 if !isCorePackage(i) {
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700218 ret = append(ret, i)
219 }
220 }
221
Steven Moreland744eb322018-07-25 16:31:08 -0700222 return ret
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700223}
224
225func hidlInterfaceMutator(mctx android.LoadHookContext, i *hidlInterface) {
226 name, err := parseFqName(i.ModuleBase.Name())
227 if err != nil {
228 mctx.PropertyErrorf("name", err.Error())
229 }
230
231 if !name.inPackage(i.properties.Root) {
Steven Moreland744eb322018-07-25 16:31:08 -0700232 mctx.PropertyErrorf("root", i.properties.Root+" must be a prefix of "+name.string()+".")
233 }
234 if lookupPackageRoot(i.properties.Root) == nil {
235 mctx.PropertyErrorf("interfaces", `Cannot find package root specification for package `+
236 `root '%s' needed for module '%s'. Either this is a mispelling of the package `+
237 `root, or a new hidl_package_root module needs to be added. For example, you can `+
238 `fix this error by adding the following to <some path>/Android.bp:
239
240hidl_package_root {
241name: "%s",
242path: "<some path>",
243}
244
245This corresponds to the "-r%s:<some path>" option that would be passed into hidl-gen.`,
246 i.properties.Root, name, i.properties.Root, i.properties.Root)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700247 }
248
249 interfaces, types, _ := processSources(mctx, i.properties.Srcs)
250
251 if len(interfaces) == 0 && len(types) == 0 {
252 mctx.PropertyErrorf("srcs", "No sources provided.")
253 }
254
255 dependencies, javaDependencies, _ := processDependencies(mctx, i.properties.Interfaces)
Steven Moreland744eb322018-07-25 16:31:08 -0700256 cppDependencies := removeCoreDependencies(mctx, dependencies)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700257
258 if mctx.Failed() {
259 return
260 }
261
Steven Morelandb49d3a72018-07-25 16:40:03 -0700262 shouldGenerateLibrary := !isCorePackage(name.string())
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700263 // explicitly true if not specified to give early warning to devs
264 shouldGenerateJava := i.properties.Gen_java == nil || *i.properties.Gen_java
265 shouldGenerateJavaConstants := i.properties.Gen_java_constants
266
267 var libraryIfExists []string
268 if shouldGenerateLibrary {
269 libraryIfExists = []string{name.string()}
270 }
271
272 // TODO(b/69002743): remove filegroups
Pirama Arumuga Nainarf43bb1e2018-04-18 11:34:56 -0700273 mctx.CreateModule(android.ModuleFactoryAdaptor(android.FileGroupFactory), &fileGroupProperties{
Steven Moreland89a9ebb2017-12-04 10:18:00 -0800274 Name: proptools.StringPtr(name.fileGroupName()),
275 Owner: i.properties.Owner,
276 Srcs: i.properties.Srcs,
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700277 })
278
Steven Moreland744eb322018-07-25 16:31:08 -0700279 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
280 Name: proptools.StringPtr(name.sourcesName()),
281 }, &hidlGenProperties{
282 Language: "c++-sources",
283 FqName: name.string(),
284 Interfaces: i.properties.Interfaces,
285 Inputs: i.properties.Srcs,
286 Outputs: concat(wrap(name.dir(), interfaces, "All.cpp"), wrap(name.dir(), types, ".cpp")),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700287 })
Steven Moreland744eb322018-07-25 16:31:08 -0700288 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
289 Name: proptools.StringPtr(name.headersName()),
290 }, &hidlGenProperties{
291 Language: "c++-headers",
292 FqName: name.string(),
293 Interfaces: i.properties.Interfaces,
294 Inputs: i.properties.Srcs,
295 Outputs: concat(wrap(name.dir()+"I", interfaces, ".h"),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700296 wrap(name.dir()+"Bs", interfaces, ".h"),
297 wrap(name.dir()+"BnHw", interfaces, ".h"),
298 wrap(name.dir()+"BpHw", interfaces, ".h"),
299 wrap(name.dir()+"IHw", interfaces, ".h"),
300 wrap(name.dir(), types, ".h"),
301 wrap(name.dir()+"hw", types, ".h")),
302 })
303
304 if shouldGenerateLibrary {
305 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
Jerry Zhangf2a93962018-05-30 17:16:05 -0700306 Name: proptools.StringPtr(name.string()),
307 Owner: i.properties.Owner,
308 Recovery_available: proptools.BoolPtr(true),
309 Vendor_available: proptools.BoolPtr(true),
310 Double_loadable: proptools.BoolPtr(isDoubleLoadable(name.string())),
311 Defaults: []string{"hidl-module-defaults"},
312 Generated_sources: []string{name.sourcesName()},
313 Generated_headers: []string{name.headersName()},
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700314 Shared_libs: concat(cppDependencies, []string{
315 "libhidlbase",
316 "libhidltransport",
317 "libhwbinder",
318 "liblog",
319 "libutils",
320 "libcutils",
321 }),
322 Export_shared_lib_headers: concat(cppDependencies, []string{
323 "libhidlbase",
324 "libhidltransport",
325 "libhwbinder",
326 "libutils",
327 }),
328 Export_generated_headers: []string{name.headersName()},
329 }, &i.properties.VndkProperties)
330 }
331
332 if shouldGenerateJava {
Steven Moreland744eb322018-07-25 16:31:08 -0700333 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
334 Name: proptools.StringPtr(name.javaSourcesName()),
335 }, &hidlGenProperties{
336 Language: "java",
337 FqName: name.string(),
338 Interfaces: i.properties.Interfaces,
339 Inputs: i.properties.Srcs,
340 Outputs: concat(wrap(name.sanitizedDir()+"I", interfaces, ".java"),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700341 wrap(name.sanitizedDir(), i.properties.Types, ".java")),
342 })
Colin Crossf5536c32018-06-26 23:29:10 -0700343 mctx.CreateModule(android.ModuleFactoryAdaptor(java.LibraryFactory), &javaProperties{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700344 Name: proptools.StringPtr(name.javaName()),
Steven Moreland89a9ebb2017-12-04 10:18:00 -0800345 Owner: i.properties.Owner,
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700346 Defaults: []string{"hidl-java-module-defaults"},
347 No_framework_libs: proptools.BoolPtr(true),
Colin Crossf5536c32018-06-26 23:29:10 -0700348 Installable: proptools.BoolPtr(true),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700349 Srcs: []string{":" + name.javaSourcesName()},
Steven Morelandfcfbeaf2018-01-29 19:34:52 -0800350 Static_libs: javaDependencies,
Colin Crossa5050552018-03-29 10:30:03 -0700351
352 // This should ideally be system_current, but android.hidl.base-V1.0-java is used
353 // to build framework, which is used to build system_current. Use core_current
354 // plus hwbinder.stubs, which together form a subset of system_current that does
355 // not depend on framework.
356 Sdk_version: proptools.StringPtr("core_current"),
357 Libs: []string{"hwbinder.stubs"},
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700358 })
359 }
360
361 if shouldGenerateJavaConstants {
Steven Moreland744eb322018-07-25 16:31:08 -0700362 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
363 Name: proptools.StringPtr(name.javaConstantsSourcesName()),
364 }, &hidlGenProperties{
365 Language: "java-constants",
366 FqName: name.string(),
367 Interfaces: i.properties.Interfaces,
368 Inputs: i.properties.Srcs,
369 Outputs: []string{name.sanitizedDir() + "Constants.java"},
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700370 })
Colin Crossf5536c32018-06-26 23:29:10 -0700371 mctx.CreateModule(android.ModuleFactoryAdaptor(java.LibraryFactory), &javaProperties{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700372 Name: proptools.StringPtr(name.javaConstantsName()),
Steven Moreland89a9ebb2017-12-04 10:18:00 -0800373 Owner: i.properties.Owner,
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700374 Defaults: []string{"hidl-java-module-defaults"},
375 No_framework_libs: proptools.BoolPtr(true),
376 Srcs: []string{":" + name.javaConstantsSourcesName()},
377 })
378 }
379
Steven Moreland744eb322018-07-25 16:31:08 -0700380 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
381 Name: proptools.StringPtr(name.adapterHelperSourcesName()),
382 }, &hidlGenProperties{
383 Language: "c++-adapter-sources",
384 FqName: name.string(),
385 Interfaces: i.properties.Interfaces,
386 Inputs: i.properties.Srcs,
387 Outputs: wrap(name.dir()+"A", concat(interfaces, types), ".cpp"),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700388 })
Steven Moreland744eb322018-07-25 16:31:08 -0700389 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
390 Name: proptools.StringPtr(name.adapterHelperHeadersName()),
391 }, &hidlGenProperties{
392 Language: "c++-adapter-headers",
393 FqName: name.string(),
394 Interfaces: i.properties.Interfaces,
395 Inputs: i.properties.Srcs,
396 Outputs: wrap(name.dir()+"A", concat(interfaces, types), ".h"),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700397 })
398
399 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProperties{
400 Name: proptools.StringPtr(name.adapterHelperName()),
Steven Moreland89a9ebb2017-12-04 10:18:00 -0800401 Owner: i.properties.Owner,
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700402 Vendor_available: proptools.BoolPtr(true),
403 Defaults: []string{"hidl-module-defaults"},
404 Generated_sources: []string{name.adapterHelperSourcesName()},
405 Generated_headers: []string{name.adapterHelperHeadersName()},
Steven Moreland10d1ec42017-11-29 13:56:28 -0800406 Shared_libs: []string{
Steven Morelandd90bdaa2018-01-03 11:12:43 -0800407 "libbase",
Steven Morelandffa25282017-11-13 14:23:25 -0800408 "libcutils",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700409 "libhidlbase",
410 "libhidltransport",
Steven Morelandffa25282017-11-13 14:23:25 -0800411 "libhwbinder",
412 "liblog",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700413 "libutils",
Steven Morelandffa25282017-11-13 14:23:25 -0800414 },
415 Static_libs: concat([]string{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700416 "libhidladapter",
417 }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists),
Steven Morelandffa25282017-11-13 14:23:25 -0800418 Export_shared_lib_headers: []string{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700419 "libhidlbase",
420 "libhidltransport",
Steven Morelandffa25282017-11-13 14:23:25 -0800421 },
422 Export_static_lib_headers: concat([]string{
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700423 "libhidladapter",
424 }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists),
425 Export_generated_headers: []string{name.adapterHelperHeadersName()},
Steven Moreland10d1ec42017-11-29 13:56:28 -0800426 Group_static_libs: proptools.BoolPtr(true),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700427 })
Steven Moreland744eb322018-07-25 16:31:08 -0700428 mctx.CreateModule(android.ModuleFactoryAdaptor(hidlGenFactory), &nameProperties{
429 Name: proptools.StringPtr(name.adapterSourcesName()),
430 }, &hidlGenProperties{
431 Language: "c++-adapter-main",
432 FqName: name.string(),
433 Interfaces: i.properties.Interfaces,
434 Inputs: i.properties.Srcs,
435 Outputs: []string{"main.cpp"},
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700436 })
437 mctx.CreateModule(android.ModuleFactoryAdaptor(cc.TestFactory), &ccProperties{
438 Name: proptools.StringPtr(name.adapterName()),
Steven Moreland89a9ebb2017-12-04 10:18:00 -0800439 Owner: i.properties.Owner,
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700440 Generated_sources: []string{name.adapterSourcesName()},
Steven Moreland10d1ec42017-11-29 13:56:28 -0800441 Shared_libs: []string{
Steven Morelandd90bdaa2018-01-03 11:12:43 -0800442 "libbase",
Steven Morelandffa25282017-11-13 14:23:25 -0800443 "libcutils",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700444 "libhidlbase",
445 "libhidltransport",
Steven Morelandffa25282017-11-13 14:23:25 -0800446 "libhwbinder",
447 "liblog",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700448 "libutils",
Steven Morelandffa25282017-11-13 14:23:25 -0800449 },
450 Static_libs: concat([]string{
451 "libhidladapter",
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700452 name.adapterHelperName(),
Steven Morelandffa25282017-11-13 14:23:25 -0800453 }, wrap("", dependencies, "-adapter-helper"), cppDependencies, libraryIfExists),
454 Group_static_libs: proptools.BoolPtr(true),
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700455 })
456}
457
458func (h *hidlInterface) Name() string {
459 return h.ModuleBase.Name() + hidlInterfaceSuffix
460}
461func (h *hidlInterface) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Steven Moreland744eb322018-07-25 16:31:08 -0700462 visited := false
463 ctx.VisitDirectDeps(func(dep android.Module) {
464 if visited {
465 panic("internal error, multiple dependencies found but only one added")
466 }
467 visited = true
Steven Moreland136abb82018-11-08 17:27:42 -0800468 h.properties.Full_root_option = dep.(*hidlPackageRoot).getFullPackageRoot()
Steven Moreland744eb322018-07-25 16:31:08 -0700469 })
470 if !visited {
471 panic("internal error, no dependencies found but dependency added")
472 }
473
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700474}
475func (h *hidlInterface) DepsMutator(ctx android.BottomUpMutatorContext) {
Steven Moreland744eb322018-07-25 16:31:08 -0700476 ctx.AddDependency(ctx.Module(), nil, h.properties.Root)
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700477}
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700478
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700479func hidlInterfaceFactory() android.Module {
480 i := &hidlInterface{}
481 i.AddProperties(&i.properties)
482 android.InitAndroidModule(i)
483 android.AddLoadHook(i, func(ctx android.LoadHookContext) { hidlInterfaceMutator(ctx, i) })
484
Steven Morelandd56e5bb2017-07-18 22:04:16 -0700485 return i
486}
487
Colin Crossf5536c32018-06-26 23:29:10 -0700488var doubleLoadablePackageNames = []string{
Jiyong Parkd26759f2018-04-09 12:22:18 +0900489 "android.hardware.configstore@",
490 "android.hardware.graphics.allocator@",
491 "android.hardware.graphics.bufferqueue@",
492 "android.hardware.media.omx@",
493 "android.hardware.media@",
494 "android.hardware.neuralnetworks@",
495 "android.hidl.allocator@",
496 "android.hidl.token@",
497}
498
499func isDoubleLoadable(name string) bool {
500 for _, pkgname := range doubleLoadablePackageNames {
501 if strings.HasPrefix(name, pkgname) {
502 return true
503 }
504 }
505 return false
506}
Steven Morelandb49d3a72018-07-25 16:40:03 -0700507
508// packages in libhidltransport
509var coreDependencyPackageNames = []string{
510 "android.hidl.base@",
511 "android.hidl.manager@",
512}
513
514func isCorePackage(name string) bool {
515 for _, pkgname := range coreDependencyPackageNames {
516 if strings.HasPrefix(name, pkgname) {
517 return true
518 }
519 }
520 return false
521}