blob: 9b3919c34349c1c4c71e46b058792d20ad947a81 [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//
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.
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
25var recoverySnapshotSingleton = SnapshotSingleton{
26 "recovery", // name
27 "SOONG_RECOVERY_SNAPSHOT_ZIP", // makeVar
28 android.OptionalPath{}, // snapshotZipFile
29 RecoverySnapshotImageSingleton, // Image
30 false, // Fake
31}
32
33func RecoverySnapshotSingleton() android.Singleton {
34 return &recoverySnapshotSingleton
35}
36
37// Determine if a dir under source tree is an SoC-owned proprietary directory based
38// on recovery snapshot configuration
39// Examples: device/, vendor/
40func isRecoveryProprietaryPath(dir string, deviceConfig android.DeviceConfig) bool {
41 return RecoverySnapshotSingleton().(*SnapshotSingleton).Image.IsProprietaryPath(dir, deviceConfig)
42}
43
44func IsRecoveryProprietaryModule(ctx android.BaseModuleContext) bool {
45
46 // Any module in a recovery proprietary path is a recovery proprietary
47 // module.
48 if isRecoveryProprietaryPath(ctx.ModuleDir(), ctx.DeviceConfig()) {
49 return true
50 }
51
52 // However if the module is not in a recovery proprietary path, it may
53 // still be a recovery proprietary module. This happens for cc modules
54 // that are excluded from the recovery snapshot, and it means that the
55 // vendor has assumed control of the framework-provided module.
56
57 if c, ok := ctx.Module().(RecoverySnapshotModuleInterface); ok {
58 if c.ExcludeFromRecoverySnapshot() {
59 return true
60 }
61 }
62
63 return false
64}
65
66var RecoverySnapshotImageName = "recovery"
67
68type RecoverySnapshotImage struct{}
69
70func (RecoverySnapshotImage) Init(ctx android.RegistrationContext) {
71 ctx.RegisterSingletonType("recovery-snapshot", RecoverySnapshotSingleton)
72}
73
74func (RecoverySnapshotImage) shouldGenerateSnapshot(ctx android.SingletonContext) bool {
75 // RECOVERY_SNAPSHOT_VERSION must be set to 'current' in order to generate a
76 // snapshot.
77 return ctx.DeviceConfig().RecoverySnapshotVersion() == "current"
78}
79
80func (RecoverySnapshotImage) InImage(m SnapshotModuleInterfaceBase) func() bool {
81 r, ok := m.(RecoverySnapshotModuleInterface)
82
83 if !ok {
84 // This module does not support recovery snapshot
85 return func() bool { return false }
86 }
87 return r.InRecovery
88}
89
90func (RecoverySnapshotImage) IsProprietaryPath(dir string, deviceConfig android.DeviceConfig) bool {
91 return isDirectoryExcluded(dir, deviceConfig.RecoverySnapshotDirsExcludedMap(), deviceConfig.RecoverySnapshotDirsIncludedMap())
92}
93
94func (RecoverySnapshotImage) ExcludeFromSnapshot(m SnapshotModuleInterfaceBase) bool {
95 r, ok := m.(RecoverySnapshotModuleInterface)
96
97 if !ok {
98 // This module does not support recovery snapshot
99 return true
100 }
101 return r.ExcludeFromRecoverySnapshot()
102}
103
104func (RecoverySnapshotImage) IsUsingSnapshot(cfg android.DeviceConfig) bool {
105 recoverySnapshotVersion := cfg.RecoverySnapshotVersion()
106 return recoverySnapshotVersion != "current" && recoverySnapshotVersion != ""
107}
108
109func (RecoverySnapshotImage) TargetSnapshotVersion(cfg android.DeviceConfig) string {
110 return cfg.RecoverySnapshotVersion()
111}
112
113func (RecoverySnapshotImage) ExcludeFromDirectedSnapshot(cfg android.DeviceConfig, name string) bool {
114 // If we're using full snapshot, not directed snapshot, capture every module
115 if !cfg.DirectedRecoverySnapshot() {
116 return false
117 }
118 // Else, checks if name is in RECOVERY_SNAPSHOT_MODULES.
119 return !cfg.RecoverySnapshotModules()[name]
120}
121
122func (RecoverySnapshotImage) ImageName() string {
123 return RecoverySnapshotImageName
124}
125
126var RecoverySnapshotImageSingleton RecoverySnapshotImage
127
128func init() {
129 RecoverySnapshotImageSingleton.Init(android.InitRegistrationContext)
130}