blob: 6dffa03a4fb43374c918b000039217f19d2b09dc [file] [log] [blame]
Inseob Kim320628f2024-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 Yune5b73762024-07-03 13:34:29 +090022import os
Inseob Kim320628f2024-06-18 11:09:12 +090023import subprocess
24import sys
25
Justin Yune5b73762024-07-03 13:34:29 +090026TEST_KEY_DIR = "build/make/target/product/security"
27
Inseob Kim320628f2024-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
Luca Stefani95895802024-09-07 11:49:03 +020048def override_config(config):
49 if "PRODUCT_BUILD_PROP_OVERRIDES" in config:
50 current_key = None
51 props_overrides = {}
52
53 for var in config["PRODUCT_BUILD_PROP_OVERRIDES"]:
54 if "=" in var:
55 current_key, value = var.split("=")
56 props_overrides[current_key] = value
57 else:
58 props_overrides[current_key] += f" {var}"
59
60 for key, value in props_overrides.items():
61 if key not in config:
62 print(f"Key \"{key}\" isn't a valid prop override", file=sys.stderr)
63 sys.exit(1)
64 config[key] = value
65
Inseob Kim320628f2024-06-18 11:09:12 +090066def parse_args():
67 """Parse commandline arguments."""
68 parser = argparse.ArgumentParser()
69 parser.add_argument("--build-fingerprint-file", required=True, type=argparse.FileType("r"))
70 parser.add_argument("--build-hostname-file", required=True, type=argparse.FileType("r"))
71 parser.add_argument("--build-number-file", required=True, type=argparse.FileType("r"))
72 parser.add_argument("--build-thumbprint-file", type=argparse.FileType("r"))
73 parser.add_argument("--build-username", required=True)
74 parser.add_argument("--date-file", required=True, type=argparse.FileType("r"))
75 parser.add_argument("--platform-preview-sdk-fingerprint-file", required=True, type=argparse.FileType("r"))
76 parser.add_argument("--prop-files", action="append", type=argparse.FileType("r"), default=[])
77 parser.add_argument("--product-config", required=True, type=argparse.FileType("r"))
78 parser.add_argument("--partition", required=True)
79 parser.add_argument("--build-broken-dup-sysprop", action="store_true", default=False)
80
81 parser.add_argument("--out", required=True, type=argparse.FileType("w"))
82
83 args = parser.parse_args()
84
85 # post process parse_args requiring manual handling
86 args.config = json.load(args.product_config)
87 config = args.config
88
89 config["BuildFlavor"] = get_build_flavor(config)
90 config["BuildKeys"] = get_build_keys(config)
91 config["BuildVariant"] = get_build_variant(config)
92
93 config["BuildFingerprint"] = args.build_fingerprint_file.read().strip()
94 config["BuildHostname"] = args.build_hostname_file.read().strip()
95 config["BuildNumber"] = args.build_number_file.read().strip()
96 config["BuildUsername"] = args.build_username
Inseob Kim66c3cba2024-06-25 19:09:12 +090097
98 build_version_tags_list = config["BuildVersionTags"]
Inseob Kim320628f2024-06-18 11:09:12 +090099 if config["BuildType"] == "debug":
Inseob Kim66c3cba2024-06-25 19:09:12 +0900100 build_version_tags_list.append("debug")
101 build_version_tags_list.append(config["BuildKeys"])
102 build_version_tags = ",".join(sorted(set(build_version_tags_list)))
103 config["BuildVersionTags"] = build_version_tags
Inseob Kim320628f2024-06-18 11:09:12 +0900104
105 raw_date = args.date_file.read().strip()
106 config["Date"] = subprocess.check_output(["date", "-d", f"@{raw_date}"], text=True).strip()
107 config["DateUtc"] = subprocess.check_output(["date", "-d", f"@{raw_date}", "+%s"], text=True).strip()
108
109 # build_desc is human readable strings that describe this build. This has the same info as the
110 # build fingerprint.
111 # e.g. "aosp_cf_x86_64_phone-userdebug VanillaIceCream MAIN eng.20240319.143939 test-keys"
112 config["BuildDesc"] = f"{config['DeviceProduct']}-{config['BuildVariant']} " \
113 f"{config['Platform_version_name']} {config['BuildId']} " \
114 f"{config['BuildNumber']} {config['BuildVersionTags']}"
115
116 config["PlatformPreviewSdkFingerprint"] = args.platform_preview_sdk_fingerprint_file.read().strip()
117
118 if args.build_thumbprint_file:
119 config["BuildThumbprint"] = args.build_thumbprint_file.read().strip()
120
basamaryana3336a42024-10-22 12:08:07 -0400121 config["LineageDesc"] = config["BuildDesc"]
Michael Bestas03a92d72024-10-20 07:20:42 +0300122 config["LineageDevice"] = config["DeviceName"]
123
Luca Stefani95895802024-09-07 11:49:03 +0200124 override_config(config)
125
Inseob Kim320628f2024-06-18 11:09:12 +0900126 append_additional_system_props(args)
127 append_additional_vendor_props(args)
128 append_additional_product_props(args)
129
130 return args
131
132def generate_common_build_props(args):
133 print("####################################")
134 print("# from generate_common_build_props")
135 print("# These properties identify this partition image.")
136 print("####################################")
137
138 config = args.config
139 partition = args.partition
140
141 if partition == "system":
142 print(f"ro.product.{partition}.brand={config['SystemBrand']}")
143 print(f"ro.product.{partition}.device={config['SystemDevice']}")
144 print(f"ro.product.{partition}.manufacturer={config['SystemManufacturer']}")
145 print(f"ro.product.{partition}.model={config['SystemModel']}")
146 print(f"ro.product.{partition}.name={config['SystemName']}")
147 else:
148 print(f"ro.product.{partition}.brand={config['ProductBrand']}")
149 print(f"ro.product.{partition}.device={config['DeviceName']}")
150 print(f"ro.product.{partition}.manufacturer={config['ProductManufacturer']}")
151 print(f"ro.product.{partition}.model={config['ProductModel']}")
152 print(f"ro.product.{partition}.name={config['DeviceProduct']}")
153
154 if partition != "system":
Inseob Kima8bc86a2024-08-05 12:51:05 +0900155 if config["ProductModelForAttestation"]:
156 print(f"ro.product.model_for_attestation={config['ProductModelForAttestation']}")
157 if config["ProductBrandForAttestation"]:
158 print(f"ro.product.brand_for_attestation={config['ProductBrandForAttestation']}")
159 if config["ProductNameForAttestation"]:
160 print(f"ro.product.name_for_attestation={config['ProductNameForAttestation']}")
161 if config["ProductDeviceForAttestation"]:
162 print(f"ro.product.device_for_attestation={config['ProductDeviceForAttestation']}")
163 if config["ProductManufacturerForAttestation"]:
164 print(f"ro.product.manufacturer_for_attestation={config['ProductManufacturerForAttestation']}")
Inseob Kim320628f2024-06-18 11:09:12 +0900165
166 if config["ZygoteForce64"]:
167 if partition == "vendor":
168 print(f"ro.{partition}.product.cpu.abilist={config['DeviceAbiList64']}")
169 print(f"ro.{partition}.product.cpu.abilist32=")
170 print(f"ro.{partition}.product.cpu.abilist64={config['DeviceAbiList64']}")
171 else:
172 if partition == "system" or partition == "vendor" or partition == "odm":
173 print(f"ro.{partition}.product.cpu.abilist={config['DeviceAbiList']}")
174 print(f"ro.{partition}.product.cpu.abilist32={config['DeviceAbiList32']}")
175 print(f"ro.{partition}.product.cpu.abilist64={config['DeviceAbiList64']}")
176
177 print(f"ro.{partition}.build.date={config['Date']}")
178 print(f"ro.{partition}.build.date.utc={config['DateUtc']}")
179 # Allow optional assignments for ARC forward-declarations (b/249168657)
180 # TODO: Remove any tag-related inconsistencies once the goals from
181 # go/arc-android-sigprop-changes have been achieved.
182 print(f"ro.{partition}.build.fingerprint?={config['BuildFingerprint']}")
183 print(f"ro.{partition}.build.id?={config['BuildId']}")
184 print(f"ro.{partition}.build.tags?={config['BuildVersionTags']}")
185 print(f"ro.{partition}.build.type={config['BuildVariant']}")
186 print(f"ro.{partition}.build.version.incremental={config['BuildNumber']}")
187 print(f"ro.{partition}.build.version.release={config['Platform_version_last_stable']}")
188 print(f"ro.{partition}.build.version.release_or_codename={config['Platform_version_name']}")
189 print(f"ro.{partition}.build.version.sdk={config['Platform_sdk_version']}")
190
191def generate_build_info(args):
192 print()
193 print("####################################")
194 print("# from gen_build_prop.py:generate_build_info")
195 print("####################################")
196 print("# begin build properties")
197
198 config = args.config
199 build_flags = config["BuildFlags"]
200
Michael Bestas849506b2024-10-17 06:10:07 +0300201 print(f"ro.build.fingerprint?={config['BuildFingerprint']}")
202
Inseob Kim320628f2024-06-18 11:09:12 +0900203 # The ro.build.id will be set dynamically by init, by appending the unique vbmeta digest.
204 if config["BoardUseVbmetaDigestInFingerprint"]:
205 print(f"ro.build.legacy.id={config['BuildId']}")
206 else:
207 print(f"ro.build.id?={config['BuildId']}")
208
209 # ro.build.display.id is shown under Settings -> About Phone
210 if config["BuildVariant"] == "user":
211 # User builds should show:
212 # release build number or branch.buld_number non-release builds
213
214 # Dev. branches should have DISPLAY_BUILD_NUMBER set
215 if config["DisplayBuildNumber"]:
Inseob Kim5c333a92024-07-19 09:25:38 +0900216 print(f"ro.build.display.id?={config['BuildId']}.{config['BuildNumber']} {config['BuildKeys']}")
Inseob Kim320628f2024-06-18 11:09:12 +0900217 else:
218 print(f"ro.build.display.id?={config['BuildId']} {config['BuildKeys']}")
219 else:
220 # Non-user builds should show detailed build information (See build desc above)
basamaryana3336a42024-10-22 12:08:07 -0400221 print(f"ro.build.display.id?={config['LineageDesc']}")
Inseob Kim320628f2024-06-18 11:09:12 +0900222 print(f"ro.build.version.incremental={config['BuildNumber']}")
223 print(f"ro.build.version.sdk={config['Platform_sdk_version']}")
224 print(f"ro.build.version.preview_sdk={config['Platform_preview_sdk_version']}")
225 print(f"ro.build.version.preview_sdk_fingerprint={config['PlatformPreviewSdkFingerprint']}")
226 print(f"ro.build.version.codename={config['Platform_sdk_codename']}")
227 print(f"ro.build.version.all_codenames={','.join(config['Platform_version_active_codenames'])}")
228 print(f"ro.build.version.known_codenames={config['Platform_version_known_codenames']}")
229 print(f"ro.build.version.release={config['Platform_version_last_stable']}")
230 print(f"ro.build.version.release_or_codename={config['Platform_version_name']}")
231 print(f"ro.build.version.release_or_preview_display={config['Platform_display_version_name']}")
232 print(f"ro.build.version.security_patch={config['Platform_security_patch']}")
233 print(f"ro.build.version.base_os={config['Platform_base_os']}")
234 print(f"ro.build.version.min_supported_target_sdk={build_flags['RELEASE_PLATFORM_MIN_SUPPORTED_TARGET_SDK_VERSION']}")
235 print(f"ro.build.date={config['Date']}")
236 print(f"ro.build.date.utc={config['DateUtc']}")
237 print(f"ro.build.type={config['BuildVariant']}")
238 print(f"ro.build.user={config['BuildUsername']}")
239 print(f"ro.build.host={config['BuildHostname']}")
240 # TODO: Remove any tag-related optional property declarations once the goals
241 # from go/arc-android-sigprop-changes have been achieved.
242 print(f"ro.build.tags?={config['BuildVersionTags']}")
243 # ro.build.flavor are used only by the test harness to distinguish builds.
244 # Only add _asan for a sanitized build if it isn't already a part of the
245 # flavor (via a dedicated lunch config for example).
246 print(f"ro.build.flavor={config['BuildFlavor']}")
247
Michael Bestas03a92d72024-10-20 07:20:42 +0300248 print(f"ro.lineage.device={config['LineageDevice']}")
249
Inseob Kim320628f2024-06-18 11:09:12 +0900250 # These values are deprecated, use "ro.product.cpu.abilist"
251 # instead (see below).
252 print(f"# ro.product.cpu.abi and ro.product.cpu.abi2 are obsolete,")
253 print(f"# use ro.product.cpu.abilist instead.")
254 print(f"ro.product.cpu.abi={config['DeviceAbi'][0]}")
255 if len(config["DeviceAbi"]) > 1:
256 print(f"ro.product.cpu.abi2={config['DeviceAbi'][1]}")
257
258 if config["ProductLocales"]:
259 print(f"ro.product.locale={config['ProductLocales'][0]}")
260 print(f"ro.wifi.channels={' '.join(config['ProductDefaultWifiChannels'])}")
261
262 print(f"# ro.build.product is obsolete; use ro.product.device")
263 print(f"ro.build.product={config['DeviceName']}")
264
265 print(f"# Do not try to parse description or thumbprint")
266 print(f"ro.build.description?={config['BuildDesc']}")
Inseob Kim4f5e9372024-07-31 07:58:23 +0900267 if "BuildThumbprint" in config:
Inseob Kim320628f2024-06-18 11:09:12 +0900268 print(f"ro.build.thumbprint={config['BuildThumbprint']}")
269
270 print(f"# end build properties")
271
272def write_properties_from_file(file):
273 print()
274 print("####################################")
275 print(f"# from {file.name}")
276 print("####################################")
277 print(file.read(), end="")
278
279def write_properties_from_variable(name, props, build_broken_dup_sysprop):
280 print()
281 print("####################################")
282 print(f"# from variable {name}")
283 print("####################################")
284
285 # Implement the legacy behavior when BUILD_BROKEN_DUP_SYSPROP is on.
286 # Optional assignments are all converted to normal assignments and
287 # when their duplicates the first one wins.
288 if build_broken_dup_sysprop:
289 processed_props = []
290 seen_props = set()
291 for line in props:
292 line = line.replace("?=", "=")
293 key, value = line.split("=", 1)
294 if key in seen_props:
295 continue
296 seen_props.add(key)
297 processed_props.append(line)
298 props = processed_props
299
300 for line in props:
301 print(line)
302
303def append_additional_system_props(args):
304 props = []
305
306 config = args.config
307
308 # Add the product-defined properties to the build properties.
Inseob Kim6d4e02d2024-07-31 02:09:34 +0000309 if not config["PropertySplitEnabled"] or not config["VendorImageFileSystemType"]:
Inseob Kim320628f2024-06-18 11:09:12 +0900310 if "PRODUCT_PROPERTY_OVERRIDES" in config:
311 props += config["PRODUCT_PROPERTY_OVERRIDES"]
312
313 props.append(f"ro.treble.enabled={'true' if config['FullTreble'] else 'false'}")
314 # Set ro.llndk.api_level to show the maximum vendor API level that the LLNDK
315 # in the system partition supports.
316 if config["VendorApiLevel"]:
317 props.append(f"ro.llndk.api_level={config['VendorApiLevel']}")
318
319 # Sets ro.actionable_compatible_property.enabled to know on runtime whether
320 # the allowed list of actionable compatible properties is enabled or not.
321 props.append("ro.actionable_compatible_property.enabled=true")
322
323 # Enable core platform API violation warnings on userdebug and eng builds.
324 if config["BuildVariant"] != "user":
325 props.append("persist.debug.dalvik.vm.core_platform_api_policy=just-warn")
326
327 # Define ro.sanitize.<name> properties for all global sanitizers.
328 for sanitize_target in config["SanitizeDevice"]:
329 props.append(f"ro.sanitize.{sanitize_target}=true")
330
331 # Sets the default value of ro.postinstall.fstab.prefix to /system.
332 # Device board config should override the value to /product when needed by:
333 #
334 # PRODUCT_PRODUCT_PROPERTIES += ro.postinstall.fstab.prefix=/product
335 #
336 # It then uses ${ro.postinstall.fstab.prefix}/etc/fstab.postinstall to
337 # mount system_other partition.
338 props.append("ro.postinstall.fstab.prefix=/system")
339
340 enable_target_debugging = True
Inseob Kim6d4e02d2024-07-31 02:09:34 +0000341 enable_dalvik_lock_contention_logging = True
Inseob Kim320628f2024-06-18 11:09:12 +0900342 if config["BuildVariant"] == "user" or config["BuildVariant"] == "userdebug":
343 # Target is secure in user builds.
344 props.append("ro.secure=1")
345 props.append("security.perf_harden=1")
346
347 if config["BuildVariant"] == "user":
348 # Disable debugging in plain user builds.
349 props.append("ro.adb.secure=1")
350 enable_target_debugging = False
Inseob Kim6d4e02d2024-07-31 02:09:34 +0000351 enable_dalvik_lock_contention_logging = False
352 else:
353 # Disable debugging in userdebug builds if PRODUCT_NOT_DEBUGGABLE_IN_USERDEBUG
354 # is set.
355 if config["ProductNotDebuggableInUserdebug"]:
356 enable_target_debugging = False
Inseob Kim320628f2024-06-18 11:09:12 +0900357
358 # Disallow mock locations by default for user builds
359 props.append("ro.allow.mock.location=0")
360 else:
361 # Turn on checkjni for non-user builds.
362 props.append("ro.kernel.android.checkjni=1")
363 # Set device insecure for non-user builds.
364 props.append("ro.secure=0")
365 # Allow mock locations by default for non user builds
366 props.append("ro.allow.mock.location=1")
367
Inseob Kim6d4e02d2024-07-31 02:09:34 +0000368 if enable_dalvik_lock_contention_logging:
Inseob Kim320628f2024-06-18 11:09:12 +0900369 # Enable Dalvik lock contention logging.
370 props.append("dalvik.vm.lockprof.threshold=500")
371
Inseob Kim6d4e02d2024-07-31 02:09:34 +0000372 if enable_target_debugging:
Inseob Kim320628f2024-06-18 11:09:12 +0900373 # Target is more debuggable and adbd is on by default
374 props.append("ro.debuggable=1")
375 else:
376 # Target is less debuggable and adbd is off by default
377 props.append("ro.debuggable=0")
378
379 if config["BuildVariant"] == "eng":
380 if "ro.setupwizard.mode=ENABLED" in props:
381 # Don't require the setup wizard on eng builds
382 props = list(filter(lambda x: not x.startswith("ro.setupwizard.mode="), props))
383 props.append("ro.setupwizard.mode=OPTIONAL")
384
385 if not config["SdkBuild"]:
386 # To speedup startup of non-preopted builds, don't verify or compile the boot image.
387 props.append("dalvik.vm.image-dex2oat-filter=extract")
388 # b/323566535
389 props.append("init.svc_debug.no_fatal.zygote=true")
390
391 if config["SdkBuild"]:
392 props.append("xmpp.auto-presence=true")
393 props.append("ro.config.nocheckin=yes")
394
395 props.append("net.bt.name=Android")
396
397 # This property is set by flashing debug boot image, so default to false.
398 props.append("ro.force.debuggable=0")
399
400 config["ADDITIONAL_SYSTEM_PROPERTIES"] = props
401
402def append_additional_vendor_props(args):
403 props = []
404
405 config = args.config
406 build_flags = config["BuildFlags"]
407
408 # Add cpu properties for bionic and ART.
409 props.append(f"ro.bionic.arch={config['DeviceArch']}")
410 props.append(f"ro.bionic.cpu_variant={config['DeviceCpuVariantRuntime']}")
411 props.append(f"ro.bionic.2nd_arch={config['DeviceSecondaryArch']}")
412 props.append(f"ro.bionic.2nd_cpu_variant={config['DeviceSecondaryCpuVariantRuntime']}")
413
414 props.append(f"persist.sys.dalvik.vm.lib.2=libart.so")
415 props.append(f"dalvik.vm.isa.{config['DeviceArch']}.variant={config['Dex2oatTargetCpuVariantRuntime']}")
416 if config["Dex2oatTargetInstructionSetFeatures"]:
417 props.append(f"dalvik.vm.isa.{config['DeviceArch']}.features={config['Dex2oatTargetInstructionSetFeatures']}")
418
419 if config["DeviceSecondaryArch"]:
420 props.append(f"dalvik.vm.isa.{config['DeviceSecondaryArch']}.variant={config['SecondaryDex2oatCpuVariantRuntime']}")
421 if config["SecondaryDex2oatInstructionSetFeatures"]:
422 props.append(f"dalvik.vm.isa.{config['DeviceSecondaryArch']}.features={config['SecondaryDex2oatInstructionSetFeatures']}")
423
424 # Although these variables are prefixed with TARGET_RECOVERY_, they are also needed under charger
425 # mode (via libminui).
426 if config["RecoveryDefaultRotation"]:
427 props.append(f"ro.minui.default_rotation={config['RecoveryDefaultRotation']}")
428
Michael Bestas85dcbe32024-10-17 17:27:05 +0300429 if config["RecoveryDefaultTouchRotation"]:
430 props.append(f"ro.minui.default_touch_rotation={config['RecoveryDefaultTouchRotation']}")
431
Inseob Kim320628f2024-06-18 11:09:12 +0900432 if config["RecoveryOverscanPercent"]:
433 props.append(f"ro.minui.overscan_percent={config['RecoveryOverscanPercent']}")
434
435 if config["RecoveryPixelFormat"]:
436 props.append(f"ro.minui.pixel_format={config['RecoveryPixelFormat']}")
437
438 if "UseDynamicPartitions" in config:
439 props.append(f"ro.boot.dynamic_partitions={'true' if config['UseDynamicPartitions'] else 'false'}")
440
441 if "RetrofitDynamicPartitions" in config:
442 props.append(f"ro.boot.dynamic_partitions_retrofit={'true' if config['RetrofitDynamicPartitions'] else 'false'}")
443
444 if config["ShippingApiLevel"]:
445 props.append(f"ro.product.first_api_level={config['ShippingApiLevel']}")
446
447 if config["ShippingVendorApiLevel"]:
448 props.append(f"ro.vendor.api_level={config['ShippingVendorApiLevel']}")
449
450 if config["BuildVariant"] != "user" and config["BuildDebugfsRestrictionsEnabled"]:
451 props.append(f"ro.product.debugfs_restrictions.enabled=true")
452
453 # Vendors with GRF must define BOARD_SHIPPING_API_LEVEL for the vendor API level.
454 # This must not be defined for the non-GRF devices.
455 # The values of the GRF properties will be verified by post_process_props.py
456 if config["BoardShippingApiLevel"]:
Inseob Kim6d4e02d2024-07-31 02:09:34 +0000457 props.append(f"ro.board.first_api_level={config['BoardShippingApiLevel']}")
Inseob Kim320628f2024-06-18 11:09:12 +0900458
459 # Build system set BOARD_API_LEVEL to show the api level of the vendor API surface.
460 # This must not be altered outside of build system.
461 if config["VendorApiLevel"]:
462 props.append(f"ro.board.api_level={config['VendorApiLevel']}")
463
464 # RELEASE_BOARD_API_LEVEL_FROZEN is true when the vendor API surface is frozen.
465 if build_flags["RELEASE_BOARD_API_LEVEL_FROZEN"]:
466 props.append(f"ro.board.api_frozen=true")
467
468 # Set build prop. This prop is read by ota_from_target_files when generating OTA,
469 # to decide if VABC should be disabled.
470 if config["DontUseVabcOta"]:
471 props.append(f"ro.vendor.build.dont_use_vabc=true")
472
473 # Set the flag in vendor. So VTS would know if the new fingerprint format is in use when
474 # the system images are replaced by GSI.
475 if config["BoardUseVbmetaDigestInFingerprint"]:
476 props.append(f"ro.vendor.build.fingerprint_has_digest=1")
477
478 props.append(f"ro.vendor.build.security_patch={config['VendorSecurityPatch']}")
479 props.append(f"ro.product.board={config['BootloaderBoardName']}")
480 props.append(f"ro.board.platform={config['BoardPlatform']}")
481 props.append(f"ro.hwui.use_vulkan={'true' if config['UsesVulkan'] else 'false'}")
482
483 if config["ScreenDensity"]:
484 props.append(f"ro.sf.lcd_density={config['ScreenDensity']}")
485
486 if "AbOtaUpdater" in config:
487 props.append(f"ro.build.ab_update={'true' if config['AbOtaUpdater'] else 'false'}")
488 if config["AbOtaUpdater"]:
489 props.append(f"ro.vendor.build.ab_ota_partitions={config['AbOtaPartitions']}")
490
491 config["ADDITIONAL_VENDOR_PROPERTIES"] = props
492
493def append_additional_product_props(args):
494 props = []
495
496 config = args.config
497
498 # Add the system server compiler filter if they are specified for the product.
499 if config["SystemServerCompilerFilter"]:
500 props.append(f"dalvik.vm.systemservercompilerfilter={config['SystemServerCompilerFilter']}")
501
502 # Add the 16K developer args if it is defined for the product.
503 props.append(f"ro.product.build.16k_page.enabled={'true' if config['Product16KDeveloperOption'] else 'false'}")
504
Inseob Kim46288272024-08-08 17:47:14 +0900505 props.append(f"ro.product.page_size={16384 if config['TargetBoots16K'] else 4096}")
506
Inseob Kim320628f2024-06-18 11:09:12 +0900507 props.append(f"ro.build.characteristics={config['AAPTCharacteristics']}")
508
509 if "AbOtaUpdater" in config and config["AbOtaUpdater"]:
510 props.append(f"ro.product.ab_ota_partitions={config['AbOtaPartitions']}")
511
512 # Set this property for VTS to skip large page size tests on unsupported devices.
513 props.append(f"ro.product.cpu.pagesize.max={config['DeviceMaxPageSizeSupported']}")
514
515 if config["NoBionicPageSizeMacro"]:
516 props.append(f"ro.product.build.no_bionic_page_size_macro=true")
517
Inseob Kim6d4e02d2024-07-31 02:09:34 +0000518 # This is a temporary system property that controls the ART module. The plan is
519 # to remove it by Aug 2025, at which time Mainline updates of the ART module
520 # will ignore it as well.
Inseob Kim320628f2024-06-18 11:09:12 +0900521 # If the value is "default", it will be mangled by post_process_props.py.
522 props.append(f"ro.dalvik.vm.enable_uffd_gc={config['EnableUffdGc']}")
523
524 config["ADDITIONAL_PRODUCT_PROPERTIES"] = props
525
526def build_system_prop(args):
527 config = args.config
528
529 # Order matters here. When there are duplicates, the last one wins.
530 # TODO(b/117892318): don't allow duplicates so that the ordering doesn't matter
531 variables = [
532 "ADDITIONAL_SYSTEM_PROPERTIES",
533 "PRODUCT_SYSTEM_PROPERTIES",
534 # TODO(b/117892318): deprecate this
535 "PRODUCT_SYSTEM_DEFAULT_PROPERTIES",
536 ]
537
538 if not config["PropertySplitEnabled"]:
539 variables += [
540 "ADDITIONAL_VENDOR_PROPERTIES",
541 "PRODUCT_VENDOR_PROPERTIES",
542 ]
543
544 build_prop(args, gen_build_info=True, gen_common_build_props=True, variables=variables)
545
Inseob Kima8bc86a2024-08-05 12:51:05 +0900546def build_system_ext_prop(args):
547 config = args.config
548
549 # Order matters here. When there are duplicates, the last one wins.
550 # TODO(b/117892318): don't allow duplicates so that the ordering doesn't matter
551 variables = ["PRODUCT_SYSTEM_EXT_PROPERTIES"]
552
553 build_prop(args, gen_build_info=False, gen_common_build_props=True, variables=variables)
554
Inseob Kim320628f2024-06-18 11:09:12 +0900555'''
556def build_vendor_prop(args):
557 config = args.config
558
559 # Order matters here. When there are duplicates, the last one wins.
560 # TODO(b/117892318): don't allow duplicates so that the ordering doesn't matter
561 variables = []
562 if config["PropertySplitEnabled"]:
563 variables += [
564 "ADDITIONAL_VENDOR_PROPERTIES",
565 "PRODUCT_VENDOR_PROPERTIES",
566 # TODO(b/117892318): deprecate this
567 "PRODUCT_DEFAULT_PROPERTY_OVERRIDES",
568 "PRODUCT_PROPERTY_OVERRIDES",
569 ]
570
571 build_prop(args, gen_build_info=False, gen_common_build_props=True, variables=variables)
Inseob Kim46288272024-08-08 17:47:14 +0900572'''
Inseob Kim320628f2024-06-18 11:09:12 +0900573
574def build_product_prop(args):
575 config = args.config
576
577 # Order matters here. When there are duplicates, the last one wins.
578 # TODO(b/117892318): don't allow duplicates so that the ordering doesn't matter
579 variables = [
580 "ADDITIONAL_PRODUCT_PROPERTIES",
581 "PRODUCT_PRODUCT_PROPERTIES",
582 ]
Inseob Kim46288272024-08-08 17:47:14 +0900583
584 gen_common_build_props = True
585
586 # Skip common /product properties generation if device released before R and
587 # has no product partition. This is the first part of the check.
588 if config["Shipping_api_level"] and int(config["Shipping_api_level"]) < 30:
589 gen_common_build_props = False
590
591 # The second part of the check - always generate common properties for the
592 # devices with product partition regardless of shipping level.
593 if config["UsesProductImage"]:
594 gen_common_build_props = True
595
Inseob Kim320628f2024-06-18 11:09:12 +0900596 build_prop(args, gen_build_info=False, gen_common_build_props=True, variables=variables)
Inseob Kim46288272024-08-08 17:47:14 +0900597
598 if config["OemProperties"]:
599 print("####################################")
600 print("# PRODUCT_OEM_PROPERTIES")
601 print("####################################")
602
603 for prop in config["OemProperties"]:
604 print(f"import /oem/oem.prop {prop}")
605
606def build_odm_prop(args):
607 variables = ["ADDITIONAL_ODM_PROPERTIES", "PRODUCT_ODM_PROPERTIES"]
608 build_prop(args, gen_build_info=False, gen_common_build_props=True, variables=variables)
Inseob Kim320628f2024-06-18 11:09:12 +0900609
610def build_prop(args, gen_build_info, gen_common_build_props, variables):
611 config = args.config
612
613 if gen_common_build_props:
614 generate_common_build_props(args)
615
616 if gen_build_info:
617 generate_build_info(args)
618
619 for prop_file in args.prop_files:
620 write_properties_from_file(prop_file)
621
622 for variable in variables:
623 if variable in config:
624 write_properties_from_variable(variable, config[variable], args.build_broken_dup_sysprop)
625
626def main():
627 args = parse_args()
628
629 with contextlib.redirect_stdout(args.out):
Inseob Kim46288272024-08-08 17:47:14 +0900630 match args.partition:
631 case "system":
632 build_system_prop(args)
633 case "system_ext":
634 build_system_ext_prop(args)
635 case "odm":
636 build_odm_prop(args)
637 case "product":
638 build_product_prop(args)
639 # case "vendor": # NOT IMPLEMENTED
640 # build_vendor_prop(args)
641 case _:
642 sys.exit(f"not supported partition {args.partition}")
Inseob Kim320628f2024-06-18 11:09:12 +0900643
644if __name__ == "__main__":
645 main()