blob: a2df41c8e16181346cad92ec2c566d1126801352 [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) {
Wei Li5c6d83b2024-10-03 05:35:03 +000040 m.SkipInstall()
41 return
42 }
43
44 m.outputPath = android.PathForModuleOut(ctx, "adb_keys").OutputPath
45 input := android.ExistentPathForSource(ctx, android.String(productVariables.AdbKeys))
46 ctx.Build(pctx, android.BuildParams{
47 Rule: android.Cp,
48 Output: m.outputPath,
49 Input: input.Path(),
50 })
51 m.installPath = android.PathForModuleInPartitionInstall(ctx, ctx.DeviceConfig().ProductPath(), "etc/security")
52 ctx.InstallFile(m.installPath, "adb_keys", m.outputPath)
53}
54
55func (m *AdbKeysModule) AndroidMkEntries() []android.AndroidMkEntries {
56 if m.IsSkipInstall() {
57 return []android.AndroidMkEntries{}
58 }
59
60 return []android.AndroidMkEntries{
61 {
62 Class: "ETC",
63 OutputFile: android.OptionalPathForPath(m.outputPath),
64 }}
65}