blob: ab114b41113fd0a93112865a5eee3bc8c5f6ff71 [file] [log] [blame]
Kiyoung Kim48f37782021-07-07 12:42:39 +09001// Copyright 2021 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//
Colin Crossd079e0b2022-08-16 10:27:33 -07007// http://www.apache.org/licenses/LICENSE-2.0
Kiyoung Kim48f37782021-07-07 12:42:39 +09008//
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.
14package snapshot
15
16import "android/soong/android"
17
18// Interface for modules which can be captured in the recovery snapshot.
19type RecoverySnapshotModuleInterface interface {
20 SnapshotModuleInterfaceBase
21 InRecovery() bool
22 ExcludeFromRecoverySnapshot() bool
23}
24
Kiyoung Kim48f37782021-07-07 12:42:39 +090025func RecoverySnapshotSingleton() android.Singleton {
Colin Cross6c7e8ff2024-01-17 11:09:16 -080026 return &SnapshotSingleton{
27 "recovery", // name
28 "SOONG_RECOVERY_SNAPSHOT_ZIP", // makeVar
29 android.OptionalPath{}, // snapshotZipFile
30 RecoverySnapshotImageSingleton, // Image
31 false, // Fake
32 }
Kiyoung Kim48f37782021-07-07 12:42:39 +090033}
34
35// Determine if a dir under source tree is an SoC-owned proprietary directory based
36// on recovery snapshot configuration
37// Examples: device/, vendor/
38func isRecoveryProprietaryPath(dir string, deviceConfig android.DeviceConfig) bool {
39 return RecoverySnapshotSingleton().(*SnapshotSingleton).Image.IsProprietaryPath(dir, deviceConfig)
40}
41
42func IsRecoveryProprietaryModule(ctx android.BaseModuleContext) bool {
43
44 // Any module in a recovery proprietary path is a recovery proprietary
45 // module.
46 if isRecoveryProprietaryPath(ctx.ModuleDir(), ctx.DeviceConfig()) {
47 return true
48 }
49
50 // However if the module is not in a recovery proprietary path, it may
51 // still be a recovery proprietary module. This happens for cc modules
52 // that are excluded from the recovery snapshot, and it means that the
53 // vendor has assumed control of the framework-provided module.
54
55 if c, ok := ctx.Module().(RecoverySnapshotModuleInterface); ok {
56 if c.ExcludeFromRecoverySnapshot() {
57 return true
58 }
59 }
60
61 return false
62}
63
64var RecoverySnapshotImageName = "recovery"
65
66type RecoverySnapshotImage struct{}
67
68func (RecoverySnapshotImage) Init(ctx android.RegistrationContext) {
LaMont Jones0c10e4d2023-05-16 00:58:37 +000069 ctx.RegisterParallelSingletonType("recovery-snapshot", RecoverySnapshotSingleton)
Kiyoung Kim48f37782021-07-07 12:42:39 +090070}
71
Jose Galmesd7d99be2021-11-05 14:04:54 -070072func (RecoverySnapshotImage) RegisterAdditionalModule(ctx android.RegistrationContext, name string, factory android.ModuleFactory) {
73 ctx.RegisterModuleType(name, factory)
74}
75
Kiyoung Kim48f37782021-07-07 12:42:39 +090076func (RecoverySnapshotImage) shouldGenerateSnapshot(ctx android.SingletonContext) bool {
77 // RECOVERY_SNAPSHOT_VERSION must be set to 'current' in order to generate a
78 // snapshot.
79 return ctx.DeviceConfig().RecoverySnapshotVersion() == "current"
80}
81
82func (RecoverySnapshotImage) InImage(m SnapshotModuleInterfaceBase) func() bool {
83 r, ok := m.(RecoverySnapshotModuleInterface)
84
85 if !ok {
86 // This module does not support recovery snapshot
87 return func() bool { return false }
88 }
89 return r.InRecovery
90}
91
92func (RecoverySnapshotImage) IsProprietaryPath(dir string, deviceConfig android.DeviceConfig) bool {
93 return isDirectoryExcluded(dir, deviceConfig.RecoverySnapshotDirsExcludedMap(), deviceConfig.RecoverySnapshotDirsIncludedMap())
94}
95
96func (RecoverySnapshotImage) ExcludeFromSnapshot(m SnapshotModuleInterfaceBase) bool {
97 r, ok := m.(RecoverySnapshotModuleInterface)
98
99 if !ok {
100 // This module does not support recovery snapshot
101 return true
102 }
103 return r.ExcludeFromRecoverySnapshot()
104}
105
106func (RecoverySnapshotImage) IsUsingSnapshot(cfg android.DeviceConfig) bool {
107 recoverySnapshotVersion := cfg.RecoverySnapshotVersion()
108 return recoverySnapshotVersion != "current" && recoverySnapshotVersion != ""
109}
110
111func (RecoverySnapshotImage) TargetSnapshotVersion(cfg android.DeviceConfig) string {
112 return cfg.RecoverySnapshotVersion()
113}
114
115func (RecoverySnapshotImage) ExcludeFromDirectedSnapshot(cfg android.DeviceConfig, name string) bool {
116 // If we're using full snapshot, not directed snapshot, capture every module
117 if !cfg.DirectedRecoverySnapshot() {
118 return false
119 }
120 // Else, checks if name is in RECOVERY_SNAPSHOT_MODULES.
121 return !cfg.RecoverySnapshotModules()[name]
122}
123
124func (RecoverySnapshotImage) ImageName() string {
125 return RecoverySnapshotImageName
126}
127
128var RecoverySnapshotImageSingleton RecoverySnapshotImage
129
130func init() {
131 RecoverySnapshotImageSingleton.Init(android.InitRegistrationContext)
132}