blob: cfcb1d502d703f370592174aa6b94ddb136062c7 [file] [log] [blame]
Wei Li5c6d83b2024-10-03 05:35:03 +00001// Copyright 2024 Google Inc. All rights reserved.
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 etc
16
17import (
18 "android/soong/android"
19)
20
21func init() {
22 android.RegisterModuleType("adb_keys", AdbKeysModuleFactory)
23}
24
25type AdbKeysModule struct {
26 android.ModuleBase
Cole Faust4e9f5922024-11-13 16:09:23 -080027 outputPath android.Path
Wei Li5c6d83b2024-10-03 05:35:03 +000028 installPath android.InstallPath
29}
30
31func AdbKeysModuleFactory() android.Module {
32 module := &AdbKeysModule{}
33 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
34 return module
35}
36
37func (m *AdbKeysModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
38 productVariables := ctx.Config().ProductVariables()
Jihoon Kang06689b12024-11-06 00:25:45 +000039
40 if !m.ProductSpecific() {
41 ctx.ModuleErrorf("adb_keys module type must set product_specific to true")
42 }
43
Wei Li5c6d83b2024-10-03 05:35:03 +000044 if !(android.Bool(productVariables.Debuggable) && len(android.String(productVariables.AdbKeys)) > 0) {
Wei Li5c6d83b2024-10-03 05:35:03 +000045 m.SkipInstall()
46 return
47 }
48
Cole Faust4e9f5922024-11-13 16:09:23 -080049 outputPath := android.PathForModuleOut(ctx, "adb_keys")
Wei Li5c6d83b2024-10-03 05:35:03 +000050 input := android.ExistentPathForSource(ctx, android.String(productVariables.AdbKeys))
51 ctx.Build(pctx, android.BuildParams{
52 Rule: android.Cp,
Cole Faust4e9f5922024-11-13 16:09:23 -080053 Output: outputPath,
Wei Li5c6d83b2024-10-03 05:35:03 +000054 Input: input.Path(),
55 })
Jihoon Kang06689b12024-11-06 00:25:45 +000056 m.installPath = android.PathForModuleInstall(ctx, "etc/security")
Cole Faust4e9f5922024-11-13 16:09:23 -080057 ctx.InstallFile(m.installPath, "adb_keys", outputPath)
58 m.outputPath = outputPath
Wei Li5c6d83b2024-10-03 05:35:03 +000059}
60
61func (m *AdbKeysModule) AndroidMkEntries() []android.AndroidMkEntries {
62 if m.IsSkipInstall() {
63 return []android.AndroidMkEntries{}
64 }
65
66 return []android.AndroidMkEntries{
67 {
68 Class: "ETC",
69 OutputFile: android.OptionalPathForPath(m.outputPath),
70 }}
71}