blob: d98f01476ea1aa6060ff0b38f2d6d900a36489e0 [file] [log] [blame]
Inseob Kim2da72af2024-06-18 11:09:12 +09001#!/usr/bin/env python3
2#
3# Copyright (C) 2024 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17"""A tool for generating {partition}/build.prop"""
18
19import argparse
20import contextlib
21import json
Justin Yunac4a7272024-07-03 13:34:29 +090022import os
Inseob Kim2da72af2024-06-18 11:09:12 +090023import subprocess
24import sys
25
Justin Yunac4a7272024-07-03 13:34:29 +090026TEST_KEY_DIR = "build/make/target/product/security"
27
Inseob Kim2da72af2024-06-18 11:09:12 +090028def get_build_variant(product_config):
29 if product_config["Eng"]:
30 return "eng"
31 elif product_config["Debuggable"]:
32 return "userdebug"
33 else:
34 return "user"
35
36def get_build_flavor(product_config):
37 build_flavor = product_config["DeviceProduct"] + "-" + get_build_variant(product_config)
38 if "address" in product_config.get("SanitizeDevice", []) and "_asan" not in build_flavor:
39 build_flavor += "_asan"
40 return build_flavor
41
42def get_build_keys(product_config):
43 default_cert = product_config.get("DefaultAppCertificate", "")
44 if default_cert == "" or default_cert == os.path.join(TEST_KEY_DIR, "testKey"):
45 return "test-keys"
46 return "dev-keys"
47
48def parse_args():
49 """Parse commandline arguments."""
50 parser = argparse.ArgumentParser()
51 parser.add_argument("--build-fingerprint-file", required=True, type=argparse.FileType("r"))
52 parser.add_argument("--build-hostname-file", required=True, type=argparse.FileType("r"))
53 parser.add_argument("--build-number-file", required=True, type=argparse.FileType("r"))
54 parser.add_argument("--build-thumbprint-file", type=argparse.FileType("r"))
55 parser.add_argument("--build-username", required=True)
56 parser.add_argument("--date-file", required=True, type=argparse.FileType("r"))
57 parser.add_argument("--platform-preview-sdk-fingerprint-file", required=True, type=argparse.FileType("r"))
58 parser.add_argument("--prop-files", action="append", type=argparse.FileType("r"), default=[])
59 parser.add_argument("--product-config", required=True, type=argparse.FileType("r"))
60 parser.add_argument("--partition", required=True)
61 parser.add_argument("--build-broken-dup-sysprop", action="store_true", default=False)
62
63 parser.add_argument("--out", required=True, type=argparse.FileType("w"))
64
65 args = parser.parse_args()
66
67 # post process parse_args requiring manual handling
68 args.config = json.load(args.product_config)
69 config = args.config
70
71 config["BuildFlavor"] = get_build_flavor(config)
72 config["BuildKeys"] = get_build_keys(config)
73 config["BuildVariant"] = get_build_variant(config)
74
75 config["BuildFingerprint"] = args.build_fingerprint_file.read().strip()
76 config["BuildHostname"] = args.build_hostname_file.read().strip()
77 config["BuildNumber"] = args.build_number_file.read().strip()
78 config["BuildUsername"] = args.build_username
Inseob Kim5a994c72024-06-25 19:09:12 +090079
80 build_version_tags_list = config["BuildVersionTags"]
Inseob Kim2da72af2024-06-18 11:09:12 +090081 if config["BuildType"] == "debug":
Inseob Kim5a994c72024-06-25 19:09:12 +090082 build_version_tags_list.append("debug")
83 build_version_tags_list.append(config["BuildKeys"])
84 build_version_tags = ",".join(sorted(set(build_version_tags_list)))
85 config["BuildVersionTags"] = build_version_tags
Inseob Kim2da72af2024-06-18 11:09:12 +090086
87 raw_date = args.date_file.read().strip()
88 config["Date"] = subprocess.check_output(["date", "-d", f"@{raw_date}"], text=True).strip()
89 config["DateUtc"] = subprocess.check_output(["date", "-d", f"@{raw_date}", "+%s"], text=True).strip()
90
91 # build_desc is human readable strings that describe this build. This has the same info as the
92 # build fingerprint.
93 # e.g. "aosp_cf_x86_64_phone-userdebug VanillaIceCream MAIN eng.20240319.143939 test-keys"
94 config["BuildDesc"] = f"{config['DeviceProduct']}-{config['BuildVariant']} " \
95 f"{config['Platform_version_name']} {config['BuildId']} " \
96 f"{config['BuildNumber']} {config['BuildVersionTags']}"
97
98 config["PlatformPreviewSdkFingerprint"] = args.platform_preview_sdk_fingerprint_file.read().strip()
99
100 if args.build_thumbprint_file:
101 config["BuildThumbprint"] = args.build_thumbprint_file.read().strip()
102
103 append_additional_system_props(args)
104 append_additional_vendor_props(args)
105 append_additional_product_props(args)
106
107 return args
108
109def generate_common_build_props(args):
110 print("####################################")
Spandan Das301c2302024-12-12 23:40:52 +0000111 print("# from generate-common-build-props")
Inseob Kim2da72af2024-06-18 11:09:12 +0900112 print("# These properties identify this partition image.")
113 print("####################################")
114
115 config = args.config
Spandan Das7cf5d502024-11-06 04:09:21 +0000116 build_flags = config["BuildFlags"]
Inseob Kim2da72af2024-06-18 11:09:12 +0900117 partition = args.partition
118
119 if partition == "system":
120 print(f"ro.product.{partition}.brand={config['SystemBrand']}")
121 print(f"ro.product.{partition}.device={config['SystemDevice']}")
122 print(f"ro.product.{partition}.manufacturer={config['SystemManufacturer']}")
123 print(f"ro.product.{partition}.model={config['SystemModel']}")
124 print(f"ro.product.{partition}.name={config['SystemName']}")
125 else:
126 print(f"ro.product.{partition}.brand={config['ProductBrand']}")
127 print(f"ro.product.{partition}.device={config['DeviceName']}")
128 print(f"ro.product.{partition}.manufacturer={config['ProductManufacturer']}")
129 print(f"ro.product.{partition}.model={config['ProductModel']}")
130 print(f"ro.product.{partition}.name={config['DeviceProduct']}")
131
132 if partition != "system":
Inseob Kimacf91742024-08-05 12:51:05 +0900133 if config["ProductModelForAttestation"]:
134 print(f"ro.product.model_for_attestation={config['ProductModelForAttestation']}")
135 if config["ProductBrandForAttestation"]:
136 print(f"ro.product.brand_for_attestation={config['ProductBrandForAttestation']}")
137 if config["ProductNameForAttestation"]:
138 print(f"ro.product.name_for_attestation={config['ProductNameForAttestation']}")
139 if config["ProductDeviceForAttestation"]:
140 print(f"ro.product.device_for_attestation={config['ProductDeviceForAttestation']}")
141 if config["ProductManufacturerForAttestation"]:
142 print(f"ro.product.manufacturer_for_attestation={config['ProductManufacturerForAttestation']}")
Inseob Kim2da72af2024-06-18 11:09:12 +0900143
144 if config["ZygoteForce64"]:
145 if partition == "vendor":
146 print(f"ro.{partition}.product.cpu.abilist={config['DeviceAbiList64']}")
147 print(f"ro.{partition}.product.cpu.abilist32=")
148 print(f"ro.{partition}.product.cpu.abilist64={config['DeviceAbiList64']}")
149 else:
150 if partition == "system" or partition == "vendor" or partition == "odm":
151 print(f"ro.{partition}.product.cpu.abilist={config['DeviceAbiList']}")
152 print(f"ro.{partition}.product.cpu.abilist32={config['DeviceAbiList32']}")
153 print(f"ro.{partition}.product.cpu.abilist64={config['DeviceAbiList64']}")
154
155 print(f"ro.{partition}.build.date={config['Date']}")
156 print(f"ro.{partition}.build.date.utc={config['DateUtc']}")
157 # Allow optional assignments for ARC forward-declarations (b/249168657)
158 # TODO: Remove any tag-related inconsistencies once the goals from
159 # go/arc-android-sigprop-changes have been achieved.
160 print(f"ro.{partition}.build.fingerprint?={config['BuildFingerprint']}")
161 print(f"ro.{partition}.build.id?={config['BuildId']}")
162 print(f"ro.{partition}.build.tags?={config['BuildVersionTags']}")
163 print(f"ro.{partition}.build.type={config['BuildVariant']}")
164 print(f"ro.{partition}.build.version.incremental={config['BuildNumber']}")
165 print(f"ro.{partition}.build.version.release={config['Platform_version_last_stable']}")
166 print(f"ro.{partition}.build.version.release_or_codename={config['Platform_version_name']}")
167 print(f"ro.{partition}.build.version.sdk={config['Platform_sdk_version']}")
Spandan Das7cf5d502024-11-06 04:09:21 +0000168 print(f"ro.{partition}.build.version.sdk_minor={build_flags['RELEASE_PLATFORM_SDK_MINOR_VERSION']}")
Inseob Kim2da72af2024-06-18 11:09:12 +0900169
170def generate_build_info(args):
171 print()
172 print("####################################")
173 print("# from gen_build_prop.py:generate_build_info")
174 print("####################################")
175 print("# begin build properties")
176
177 config = args.config
178 build_flags = config["BuildFlags"]
179
180 # The ro.build.id will be set dynamically by init, by appending the unique vbmeta digest.
181 if config["BoardUseVbmetaDigestInFingerprint"]:
182 print(f"ro.build.legacy.id={config['BuildId']}")
183 else:
184 print(f"ro.build.id?={config['BuildId']}")
185
186 # ro.build.display.id is shown under Settings -> About Phone
187 if config["BuildVariant"] == "user":
188 # User builds should show:
189 # release build number or branch.buld_number non-release builds
190
191 # Dev. branches should have DISPLAY_BUILD_NUMBER set
192 if config["DisplayBuildNumber"]:
Inseob Kim51d3a6d2024-07-19 09:25:38 +0900193 print(f"ro.build.display.id?={config['BuildId']}.{config['BuildNumber']} {config['BuildKeys']}")
Inseob Kim2da72af2024-06-18 11:09:12 +0900194 else:
195 print(f"ro.build.display.id?={config['BuildId']} {config['BuildKeys']}")
196 else:
197 # Non-user builds should show detailed build information (See build desc above)
198 print(f"ro.build.display.id?={config['BuildDesc']}")
199 print(f"ro.build.version.incremental={config['BuildNumber']}")
200 print(f"ro.build.version.sdk={config['Platform_sdk_version']}")
MÃ¥rten Kongstadcdf8fd72024-06-25 16:10:27 +0200201 print(f"ro.build.version.sdk_minor={build_flags['RELEASE_PLATFORM_SDK_MINOR_VERSION']}")
Inseob Kim2da72af2024-06-18 11:09:12 +0900202 print(f"ro.build.version.preview_sdk={config['Platform_preview_sdk_version']}")
203 print(f"ro.build.version.preview_sdk_fingerprint={config['PlatformPreviewSdkFingerprint']}")
204 print(f"ro.build.version.codename={config['Platform_sdk_codename']}")
205 print(f"ro.build.version.all_codenames={','.join(config['Platform_version_active_codenames'])}")
206 print(f"ro.build.version.known_codenames={config['Platform_version_known_codenames']}")
207 print(f"ro.build.version.release={config['Platform_version_last_stable']}")
208 print(f"ro.build.version.release_or_codename={config['Platform_version_name']}")
209 print(f"ro.build.version.release_or_preview_display={config['Platform_display_version_name']}")
210 print(f"ro.build.version.security_patch={config['Platform_security_patch']}")
211 print(f"ro.build.version.base_os={config['Platform_base_os']}")
212 print(f"ro.build.version.min_supported_target_sdk={build_flags['RELEASE_PLATFORM_MIN_SUPPORTED_TARGET_SDK_VERSION']}")
213 print(f"ro.build.date={config['Date']}")
214 print(f"ro.build.date.utc={config['DateUtc']}")
215 print(f"ro.build.type={config['BuildVariant']}")
216 print(f"ro.build.user={config['BuildUsername']}")
217 print(f"ro.build.host={config['BuildHostname']}")
218 # TODO: Remove any tag-related optional property declarations once the goals
219 # from go/arc-android-sigprop-changes have been achieved.
220 print(f"ro.build.tags?={config['BuildVersionTags']}")
221 # ro.build.flavor are used only by the test harness to distinguish builds.
222 # Only add _asan for a sanitized build if it isn't already a part of the
223 # flavor (via a dedicated lunch config for example).
224 print(f"ro.build.flavor={config['BuildFlavor']}")
225
226 # These values are deprecated, use "ro.product.cpu.abilist"
227 # instead (see below).
228 print(f"# ro.product.cpu.abi and ro.product.cpu.abi2 are obsolete,")
229 print(f"# use ro.product.cpu.abilist instead.")
230 print(f"ro.product.cpu.abi={config['DeviceAbi'][0]}")
231 if len(config["DeviceAbi"]) > 1:
232 print(f"ro.product.cpu.abi2={config['DeviceAbi'][1]}")
233
234 if config["ProductLocales"]:
235 print(f"ro.product.locale={config['ProductLocales'][0]}")
236 print(f"ro.wifi.channels={' '.join(config['ProductDefaultWifiChannels'])}")
237
238 print(f"# ro.build.product is obsolete; use ro.product.device")
239 print(f"ro.build.product={config['DeviceName']}")
240
241 print(f"# Do not try to parse description or thumbprint")
242 print(f"ro.build.description?={config['BuildDesc']}")
Inseob Kim60f26362024-07-31 07:58:23 +0900243 if "BuildThumbprint" in config:
Inseob Kim2da72af2024-06-18 11:09:12 +0900244 print(f"ro.build.thumbprint={config['BuildThumbprint']}")
245
246 print(f"# end build properties")
247
248def write_properties_from_file(file):
Spandan Das301c2302024-12-12 23:40:52 +0000249 # Make and Soong use different intermediate files to build vendor/build.prop.
250 # Although the sysprop contents are same, the absolute paths of these
251 # intermediate files are different.
252 # Print the filename for the intermediate files (files in OUT_DIR).
253 # This helps with validating mk->soong migration of android partitions.
254 filename = os.path.basename(file.name) if file.name.startswith(os.environ.get("OUT_DIR")) else file.name
Inseob Kim2da72af2024-06-18 11:09:12 +0900255 print()
256 print("####################################")
Spandan Das301c2302024-12-12 23:40:52 +0000257 print(f"# from {filename}")
Inseob Kim2da72af2024-06-18 11:09:12 +0900258 print("####################################")
259 print(file.read(), end="")
260
261def write_properties_from_variable(name, props, build_broken_dup_sysprop):
262 print()
263 print("####################################")
264 print(f"# from variable {name}")
265 print("####################################")
266
267 # Implement the legacy behavior when BUILD_BROKEN_DUP_SYSPROP is on.
268 # Optional assignments are all converted to normal assignments and
269 # when their duplicates the first one wins.
270 if build_broken_dup_sysprop:
271 processed_props = []
272 seen_props = set()
273 for line in props:
274 line = line.replace("?=", "=")
275 key, value = line.split("=", 1)
276 if key in seen_props:
277 continue
278 seen_props.add(key)
279 processed_props.append(line)
280 props = processed_props
281
282 for line in props:
283 print(line)
284
285def append_additional_system_props(args):
286 props = []
287
288 config = args.config
289
290 # Add the product-defined properties to the build properties.
Inseob Kim28874822024-07-31 02:09:34 +0000291 if not config["PropertySplitEnabled"] or not config["VendorImageFileSystemType"]:
Inseob Kim2da72af2024-06-18 11:09:12 +0900292 if "PRODUCT_PROPERTY_OVERRIDES" in config:
293 props += config["PRODUCT_PROPERTY_OVERRIDES"]
294
295 props.append(f"ro.treble.enabled={'true' if config['FullTreble'] else 'false'}")
296 # Set ro.llndk.api_level to show the maximum vendor API level that the LLNDK
297 # in the system partition supports.
298 if config["VendorApiLevel"]:
299 props.append(f"ro.llndk.api_level={config['VendorApiLevel']}")
300
301 # Sets ro.actionable_compatible_property.enabled to know on runtime whether
302 # the allowed list of actionable compatible properties is enabled or not.
303 props.append("ro.actionable_compatible_property.enabled=true")
304
305 # Enable core platform API violation warnings on userdebug and eng builds.
306 if config["BuildVariant"] != "user":
307 props.append("persist.debug.dalvik.vm.core_platform_api_policy=just-warn")
308
309 # Define ro.sanitize.<name> properties for all global sanitizers.
310 for sanitize_target in config["SanitizeDevice"]:
311 props.append(f"ro.sanitize.{sanitize_target}=true")
312
313 # Sets the default value of ro.postinstall.fstab.prefix to /system.
314 # Device board config should override the value to /product when needed by:
315 #
316 # PRODUCT_PRODUCT_PROPERTIES += ro.postinstall.fstab.prefix=/product
317 #
318 # It then uses ${ro.postinstall.fstab.prefix}/etc/fstab.postinstall to
319 # mount system_other partition.
320 props.append("ro.postinstall.fstab.prefix=/system")
321
322 enable_target_debugging = True
Inseob Kim28874822024-07-31 02:09:34 +0000323 enable_dalvik_lock_contention_logging = True
Inseob Kim2da72af2024-06-18 11:09:12 +0900324 if config["BuildVariant"] == "user" or config["BuildVariant"] == "userdebug":
325 # Target is secure in user builds.
326 props.append("ro.secure=1")
327 props.append("security.perf_harden=1")
328
329 if config["BuildVariant"] == "user":
330 # Disable debugging in plain user builds.
331 props.append("ro.adb.secure=1")
332 enable_target_debugging = False
Inseob Kim28874822024-07-31 02:09:34 +0000333 enable_dalvik_lock_contention_logging = False
334 else:
335 # Disable debugging in userdebug builds if PRODUCT_NOT_DEBUGGABLE_IN_USERDEBUG
336 # is set.
337 if config["ProductNotDebuggableInUserdebug"]:
338 enable_target_debugging = False
Inseob Kim2da72af2024-06-18 11:09:12 +0900339
340 # Disallow mock locations by default for user builds
341 props.append("ro.allow.mock.location=0")
342 else:
343 # Turn on checkjni for non-user builds.
344 props.append("ro.kernel.android.checkjni=1")
345 # Set device insecure for non-user builds.
346 props.append("ro.secure=0")
347 # Allow mock locations by default for non user builds
348 props.append("ro.allow.mock.location=1")
349
Inseob Kim28874822024-07-31 02:09:34 +0000350 if enable_dalvik_lock_contention_logging:
Inseob Kim2da72af2024-06-18 11:09:12 +0900351 # Enable Dalvik lock contention logging.
352 props.append("dalvik.vm.lockprof.threshold=500")
353
Inseob Kim28874822024-07-31 02:09:34 +0000354 if enable_target_debugging:
Inseob Kim2da72af2024-06-18 11:09:12 +0900355 # Target is more debuggable and adbd is on by default
356 props.append("ro.debuggable=1")
357 else:
358 # Target is less debuggable and adbd is off by default
359 props.append("ro.debuggable=0")
360
361 if config["BuildVariant"] == "eng":
362 if "ro.setupwizard.mode=ENABLED" in props:
363 # Don't require the setup wizard on eng builds
364 props = list(filter(lambda x: not x.startswith("ro.setupwizard.mode="), props))
365 props.append("ro.setupwizard.mode=OPTIONAL")
366
367 if not config["SdkBuild"]:
368 # To speedup startup of non-preopted builds, don't verify or compile the boot image.
369 props.append("dalvik.vm.image-dex2oat-filter=extract")
370 # b/323566535
371 props.append("init.svc_debug.no_fatal.zygote=true")
372
373 if config["SdkBuild"]:
374 props.append("xmpp.auto-presence=true")
375 props.append("ro.config.nocheckin=yes")
376
377 props.append("net.bt.name=Android")
378
379 # This property is set by flashing debug boot image, so default to false.
380 props.append("ro.force.debuggable=0")
381
382 config["ADDITIONAL_SYSTEM_PROPERTIES"] = props
383
384def append_additional_vendor_props(args):
385 props = []
386
387 config = args.config
388 build_flags = config["BuildFlags"]
389
390 # Add cpu properties for bionic and ART.
391 props.append(f"ro.bionic.arch={config['DeviceArch']}")
392 props.append(f"ro.bionic.cpu_variant={config['DeviceCpuVariantRuntime']}")
393 props.append(f"ro.bionic.2nd_arch={config['DeviceSecondaryArch']}")
394 props.append(f"ro.bionic.2nd_cpu_variant={config['DeviceSecondaryCpuVariantRuntime']}")
395
396 props.append(f"persist.sys.dalvik.vm.lib.2=libart.so")
397 props.append(f"dalvik.vm.isa.{config['DeviceArch']}.variant={config['Dex2oatTargetCpuVariantRuntime']}")
398 if config["Dex2oatTargetInstructionSetFeatures"]:
399 props.append(f"dalvik.vm.isa.{config['DeviceArch']}.features={config['Dex2oatTargetInstructionSetFeatures']}")
400
401 if config["DeviceSecondaryArch"]:
402 props.append(f"dalvik.vm.isa.{config['DeviceSecondaryArch']}.variant={config['SecondaryDex2oatCpuVariantRuntime']}")
403 if config["SecondaryDex2oatInstructionSetFeatures"]:
404 props.append(f"dalvik.vm.isa.{config['DeviceSecondaryArch']}.features={config['SecondaryDex2oatInstructionSetFeatures']}")
405
406 # Although these variables are prefixed with TARGET_RECOVERY_, they are also needed under charger
407 # mode (via libminui).
408 if config["RecoveryDefaultRotation"]:
409 props.append(f"ro.minui.default_rotation={config['RecoveryDefaultRotation']}")
410
411 if config["RecoveryOverscanPercent"]:
412 props.append(f"ro.minui.overscan_percent={config['RecoveryOverscanPercent']}")
413
414 if config["RecoveryPixelFormat"]:
415 props.append(f"ro.minui.pixel_format={config['RecoveryPixelFormat']}")
416
417 if "UseDynamicPartitions" in config:
418 props.append(f"ro.boot.dynamic_partitions={'true' if config['UseDynamicPartitions'] else 'false'}")
419
420 if "RetrofitDynamicPartitions" in config:
421 props.append(f"ro.boot.dynamic_partitions_retrofit={'true' if config['RetrofitDynamicPartitions'] else 'false'}")
422
423 if config["ShippingApiLevel"]:
424 props.append(f"ro.product.first_api_level={config['ShippingApiLevel']}")
425
426 if config["ShippingVendorApiLevel"]:
427 props.append(f"ro.vendor.api_level={config['ShippingVendorApiLevel']}")
428
429 if config["BuildVariant"] != "user" and config["BuildDebugfsRestrictionsEnabled"]:
430 props.append(f"ro.product.debugfs_restrictions.enabled=true")
431
432 # Vendors with GRF must define BOARD_SHIPPING_API_LEVEL for the vendor API level.
433 # This must not be defined for the non-GRF devices.
434 # The values of the GRF properties will be verified by post_process_props.py
435 if config["BoardShippingApiLevel"]:
Inseob Kim28874822024-07-31 02:09:34 +0000436 props.append(f"ro.board.first_api_level={config['BoardShippingApiLevel']}")
Inseob Kim2da72af2024-06-18 11:09:12 +0900437
438 # Build system set BOARD_API_LEVEL to show the api level of the vendor API surface.
439 # This must not be altered outside of build system.
440 if config["VendorApiLevel"]:
Justin Yun3f84f6e2024-10-24 09:20:48 +0900441 props.append(f"ro.board.api_level?={config['VendorApiLevel']}")
442 if config["VendorApiLevelPropOverride"]:
443 props.append(f"ro.board.api_level={config['VendorApiLevelPropOverride']}")
Inseob Kim2da72af2024-06-18 11:09:12 +0900444
445 # RELEASE_BOARD_API_LEVEL_FROZEN is true when the vendor API surface is frozen.
446 if build_flags["RELEASE_BOARD_API_LEVEL_FROZEN"]:
447 props.append(f"ro.board.api_frozen=true")
448
449 # Set build prop. This prop is read by ota_from_target_files when generating OTA,
450 # to decide if VABC should be disabled.
451 if config["DontUseVabcOta"]:
452 props.append(f"ro.vendor.build.dont_use_vabc=true")
453
454 # Set the flag in vendor. So VTS would know if the new fingerprint format is in use when
455 # the system images are replaced by GSI.
456 if config["BoardUseVbmetaDigestInFingerprint"]:
457 props.append(f"ro.vendor.build.fingerprint_has_digest=1")
458
459 props.append(f"ro.vendor.build.security_patch={config['VendorSecurityPatch']}")
460 props.append(f"ro.product.board={config['BootloaderBoardName']}")
461 props.append(f"ro.board.platform={config['BoardPlatform']}")
Spandan Das876c1c92024-12-06 20:37:05 +0000462 props.append(f"ro.hwui.use_vulkan={config['UsesVulkan']}")
Inseob Kim2da72af2024-06-18 11:09:12 +0900463
464 if config["ScreenDensity"]:
465 props.append(f"ro.sf.lcd_density={config['ScreenDensity']}")
466
467 if "AbOtaUpdater" in config:
468 props.append(f"ro.build.ab_update={'true' if config['AbOtaUpdater'] else 'false'}")
469 if config["AbOtaUpdater"]:
470 props.append(f"ro.vendor.build.ab_ota_partitions={config['AbOtaPartitions']}")
471
472 config["ADDITIONAL_VENDOR_PROPERTIES"] = props
473
474def append_additional_product_props(args):
475 props = []
476
477 config = args.config
478
479 # Add the system server compiler filter if they are specified for the product.
480 if config["SystemServerCompilerFilter"]:
481 props.append(f"dalvik.vm.systemservercompilerfilter={config['SystemServerCompilerFilter']}")
482
483 # Add the 16K developer args if it is defined for the product.
484 props.append(f"ro.product.build.16k_page.enabled={'true' if config['Product16KDeveloperOption'] else 'false'}")
485
Inseob Kim01d4f8b2024-08-08 17:47:14 +0900486 props.append(f"ro.product.page_size={16384 if config['TargetBoots16K'] else 4096}")
487
Inseob Kim2da72af2024-06-18 11:09:12 +0900488 props.append(f"ro.build.characteristics={config['AAPTCharacteristics']}")
489
490 if "AbOtaUpdater" in config and config["AbOtaUpdater"]:
491 props.append(f"ro.product.ab_ota_partitions={config['AbOtaPartitions']}")
492
493 # Set this property for VTS to skip large page size tests on unsupported devices.
494 props.append(f"ro.product.cpu.pagesize.max={config['DeviceMaxPageSizeSupported']}")
495
496 if config["NoBionicPageSizeMacro"]:
497 props.append(f"ro.product.build.no_bionic_page_size_macro=true")
498
Inseob Kim28874822024-07-31 02:09:34 +0000499 # This is a temporary system property that controls the ART module. The plan is
500 # to remove it by Aug 2025, at which time Mainline updates of the ART module
501 # will ignore it as well.
Inseob Kim2da72af2024-06-18 11:09:12 +0900502 # If the value is "default", it will be mangled by post_process_props.py.
503 props.append(f"ro.dalvik.vm.enable_uffd_gc={config['EnableUffdGc']}")
504
505 config["ADDITIONAL_PRODUCT_PROPERTIES"] = props
506
507def build_system_prop(args):
508 config = args.config
509
510 # Order matters here. When there are duplicates, the last one wins.
511 # TODO(b/117892318): don't allow duplicates so that the ordering doesn't matter
512 variables = [
513 "ADDITIONAL_SYSTEM_PROPERTIES",
514 "PRODUCT_SYSTEM_PROPERTIES",
515 # TODO(b/117892318): deprecate this
516 "PRODUCT_SYSTEM_DEFAULT_PROPERTIES",
517 ]
518
519 if not config["PropertySplitEnabled"]:
520 variables += [
521 "ADDITIONAL_VENDOR_PROPERTIES",
522 "PRODUCT_VENDOR_PROPERTIES",
523 ]
524
525 build_prop(args, gen_build_info=True, gen_common_build_props=True, variables=variables)
526
Inseob Kimacf91742024-08-05 12:51:05 +0900527def build_system_ext_prop(args):
528 config = args.config
529
530 # Order matters here. When there are duplicates, the last one wins.
531 # TODO(b/117892318): don't allow duplicates so that the ordering doesn't matter
532 variables = ["PRODUCT_SYSTEM_EXT_PROPERTIES"]
533
534 build_prop(args, gen_build_info=False, gen_common_build_props=True, variables=variables)
535
Inseob Kim2da72af2024-06-18 11:09:12 +0900536def build_vendor_prop(args):
537 config = args.config
538
539 # Order matters here. When there are duplicates, the last one wins.
540 # TODO(b/117892318): don't allow duplicates so that the ordering doesn't matter
541 variables = []
542 if config["PropertySplitEnabled"]:
543 variables += [
544 "ADDITIONAL_VENDOR_PROPERTIES",
545 "PRODUCT_VENDOR_PROPERTIES",
546 # TODO(b/117892318): deprecate this
547 "PRODUCT_DEFAULT_PROPERTY_OVERRIDES",
548 "PRODUCT_PROPERTY_OVERRIDES",
549 ]
550
551 build_prop(args, gen_build_info=False, gen_common_build_props=True, variables=variables)
552
553def build_product_prop(args):
554 config = args.config
555
556 # Order matters here. When there are duplicates, the last one wins.
557 # TODO(b/117892318): don't allow duplicates so that the ordering doesn't matter
558 variables = [
559 "ADDITIONAL_PRODUCT_PROPERTIES",
560 "PRODUCT_PRODUCT_PROPERTIES",
561 ]
Inseob Kim01d4f8b2024-08-08 17:47:14 +0900562
563 gen_common_build_props = True
564
565 # Skip common /product properties generation if device released before R and
566 # has no product partition. This is the first part of the check.
567 if config["Shipping_api_level"] and int(config["Shipping_api_level"]) < 30:
568 gen_common_build_props = False
569
570 # The second part of the check - always generate common properties for the
571 # devices with product partition regardless of shipping level.
572 if config["UsesProductImage"]:
573 gen_common_build_props = True
574
Inseob Kim2da72af2024-06-18 11:09:12 +0900575 build_prop(args, gen_build_info=False, gen_common_build_props=True, variables=variables)
Inseob Kim01d4f8b2024-08-08 17:47:14 +0900576
577 if config["OemProperties"]:
578 print("####################################")
579 print("# PRODUCT_OEM_PROPERTIES")
580 print("####################################")
581
582 for prop in config["OemProperties"]:
583 print(f"import /oem/oem.prop {prop}")
584
585def build_odm_prop(args):
586 variables = ["ADDITIONAL_ODM_PROPERTIES", "PRODUCT_ODM_PROPERTIES"]
587 build_prop(args, gen_build_info=False, gen_common_build_props=True, variables=variables)
Inseob Kim2da72af2024-06-18 11:09:12 +0900588
589def build_prop(args, gen_build_info, gen_common_build_props, variables):
590 config = args.config
591
592 if gen_common_build_props:
593 generate_common_build_props(args)
594
595 if gen_build_info:
596 generate_build_info(args)
597
598 for prop_file in args.prop_files:
599 write_properties_from_file(prop_file)
600
601 for variable in variables:
602 if variable in config:
603 write_properties_from_variable(variable, config[variable], args.build_broken_dup_sysprop)
604
605def main():
606 args = parse_args()
607
608 with contextlib.redirect_stdout(args.out):
Inseob Kim01d4f8b2024-08-08 17:47:14 +0900609 match args.partition:
610 case "system":
611 build_system_prop(args)
612 case "system_ext":
613 build_system_ext_prop(args)
614 case "odm":
615 build_odm_prop(args)
616 case "product":
617 build_product_prop(args)
Spandan Das859cdef2024-10-25 21:06:18 +0000618 case "vendor":
619 build_vendor_prop(args)
Cole Faust4385d352024-11-12 15:13:37 -0800620 case "system_dlkm" | "vendor_dlkm" | "odm_dlkm" | "bootimage":
Spandan Dasb9cef3b2024-11-06 22:08:28 +0000621 build_prop(args, gen_build_info=False, gen_common_build_props=True, variables=[])
Inseob Kim01d4f8b2024-08-08 17:47:14 +0900622 case _:
623 sys.exit(f"not supported partition {args.partition}")
Inseob Kim2da72af2024-06-18 11:09:12 +0900624
625if __name__ == "__main__":
626 main()