blob: 1bce2f124b301866b1ed435e3142db6bd9d0ce11 [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
27 outputPath android.OutputPath
28 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()
39 if !(android.Bool(productVariables.Debuggable) && len(android.String(productVariables.AdbKeys)) > 0) {
40 m.Disable()
41 m.SkipInstall()
42 return
43 }
44
45 m.outputPath = android.PathForModuleOut(ctx, "adb_keys").OutputPath
46 input := android.ExistentPathForSource(ctx, android.String(productVariables.AdbKeys))
47 ctx.Build(pctx, android.BuildParams{
48 Rule: android.Cp,
49 Output: m.outputPath,
50 Input: input.Path(),
51 })
52 m.installPath = android.PathForModuleInPartitionInstall(ctx, ctx.DeviceConfig().ProductPath(), "etc/security")
53 ctx.InstallFile(m.installPath, "adb_keys", m.outputPath)
54}
55
56func (m *AdbKeysModule) AndroidMkEntries() []android.AndroidMkEntries {
57 if m.IsSkipInstall() {
58 return []android.AndroidMkEntries{}
59 }
60
61 return []android.AndroidMkEntries{
62 {
63 Class: "ETC",
64 OutputFile: android.OptionalPathForPath(m.outputPath),
65 }}
66}