Jihoon Kang | 4589337 | 2024-12-04 00:15:36 +0000 | [diff] [blame] | 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 | |
| 15 | package fsgen |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
Jihoon Kang | 0a45389 | 2024-12-09 22:16:26 +0000 | [diff] [blame^] | 19 | "android/soong/filesystem" |
Jihoon Kang | 4589337 | 2024-12-04 00:15:36 +0000 | [diff] [blame] | 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 |
| 27 | func 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 | } |
Jihoon Kang | 0a45389 | 2024-12-09 22:16:26 +0000 | [diff] [blame^] | 62 | |
| 63 | // Returns a new list of symlinks with prefix added to the dest directory for all symlinks |
| 64 | func symlinksWithNamePrefix(symlinks []filesystem.SymlinkDefinition, prefix string) []filesystem.SymlinkDefinition { |
| 65 | ret := make([]filesystem.SymlinkDefinition, len(symlinks)) |
| 66 | for i, symlink := range symlinks { |
| 67 | ret[i] = symlink.CopyWithNamePrefix(prefix) |
| 68 | } |
| 69 | return ret |
| 70 | } |