xref: /aosp_15_r20/build/soong/etc/adb_keys.go (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
1// 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.Path
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
40	if !m.ProductSpecific() {
41		ctx.ModuleErrorf("adb_keys module type must set product_specific to true")
42	}
43
44	if !(android.Bool(productVariables.Debuggable) && len(android.String(productVariables.AdbKeys)) > 0) {
45		m.SkipInstall()
46		return
47	}
48
49	outputPath := android.PathForModuleOut(ctx, "adb_keys")
50	input := android.ExistentPathForSource(ctx, android.String(productVariables.AdbKeys))
51	ctx.Build(pctx, android.BuildParams{
52		Rule:   android.Cp,
53		Output: outputPath,
54		Input:  input.Path(),
55	})
56	m.installPath = android.PathForModuleInstall(ctx, "etc/security")
57	ctx.InstallFile(m.installPath, "adb_keys", outputPath)
58	m.outputPath = outputPath
59}
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}
72