• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2024 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.
14
15package fsgen
16
17import (
18	"android/soong/android"
19	"android/soong/filesystem"
20	"fmt"
21	"strconv"
22	"strings"
23)
24
25// Returns the appropriate dpi for recovery common resources selection. Replicates the logic in
26// https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=2536;drc=a6af369e71ded123734523ea640b97b70a557cb9
27func getDpi(ctx android.LoadHookContext) string {
28	recoveryDensity := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.TargetScreenDensity
29	if len(recoveryDensity) == 0 {
30		aaptPreferredConfig := ctx.Config().ProductAAPTPreferredConfig()
31		if len(aaptPreferredConfig) > 0 {
32			recoveryDensity = aaptPreferredConfig
33		} else {
34			recoveryDensity = "mdpi"
35		}
36	}
37	if !android.InList(recoveryDensity, []string{"xxxhdpi", "xxhdpi", "xhdpi", "hdpi", "mdpi"}) {
38		recoveryDensity = strings.TrimSuffix(recoveryDensity, "dpi")
39		dpiInt, err := strconv.ParseInt(recoveryDensity, 10, 64)
40		if err != nil {
41			panic(fmt.Sprintf("Error in parsing recoveryDensity: %s", err.Error()))
42		}
43		if dpiInt >= 560 {
44			recoveryDensity = "xxxhdpi"
45		} else if dpiInt >= 400 {
46			recoveryDensity = "xxhdpi"
47		} else if dpiInt >= 280 {
48			recoveryDensity = "xhdpi"
49		} else if dpiInt >= 200 {
50			recoveryDensity = "hdpi"
51		} else {
52			recoveryDensity = "mdpi"
53		}
54	}
55
56	if p := android.ExistentPathForSource(ctx, fmt.Sprintf("bootable/recovery/res-%s", recoveryDensity)); !p.Valid() {
57		recoveryDensity = "xhdpi"
58	}
59
60	return recoveryDensity
61}
62
63// Returns the name of the appropriate prebuilt module for installing font.png file.
64// https://cs.android.com/android/platform/superproject/main/+/main:build/make/core/Makefile;l=2536;drc=a6af369e71ded123734523ea640b97b70a557cb9
65func getRecoveryFontModuleName(ctx android.LoadHookContext) string {
66	if android.InList(getDpi(ctx), []string{"xxxhdpi", "xxhdpi", "xhdpi"}) {
67		return "recovery-fonts-18"
68	}
69	return "recovery-fonts-12"
70}
71
72// Returns a new list of symlinks with prefix added to the dest directory for all symlinks
73func symlinksWithNamePrefix(symlinks []filesystem.SymlinkDefinition, prefix string) []filesystem.SymlinkDefinition {
74	ret := make([]filesystem.SymlinkDefinition, len(symlinks))
75	for i, symlink := range symlinks {
76		ret[i] = symlink.CopyWithNamePrefix(prefix)
77	}
78	return ret
79}
80