Search code examples
androidandroid-sourceandroid-kernel

Change the output of "getprop" in android adb shell


I am trying to change the output when we are using getprop in adb. I know that the init will read the system properties from /default.prop /system/build.prop /system/default.prop /data/local.prop. In my case, I only got the /default.prop and /system/build.prop. So what I did is get the android source code and add this to the build/target/product/core.mk.

PRODUCT_PROPERTY_OVERRIDES :=\
ro.bootloader="PWN" \
ro.bootmode="PWN" \
ro.hardware="PWN" \
ro.kernel.qemu="PWN" \
ro.product.device="PWN" \
ro.product.model="PWN" \
ro.product.name="PWN" 

After that, I compile the source code. But the result is weird. I can see that the system/build.prop has changed.

# begin build properties
# autogenerated by buildinfo.sh   
ro.build.id=N2G47F
ro.build.display.id=aosp_arm-eng 7.1.2 N2G47F eng.sam.20180525.204329 
test-keys 
ro.build.version.incremental=eng.sam.20180525.204329
ro.build.version.sdk=25
ro.build.version.preview_sdk=0
ro.build.version.codename=REL
ro.build.version.all_codenames=REL
ro.build.version.release=7.1.2
ro.build.version.security_patch=2017-04-05
ro.build.version.base_os=
ro.build.date=Fri May 25 20:43:29 CST 2018
ro.build.date.utc=1527252209
ro.build.type=eng
ro.build.user=sam
ro.build.host=ubuntu
ro.build.tags=test-keys
ro.build.flavor=aosp_arm-eng
ro.product.model=AOSP on ARM Emulator
ro.product.brand=Android
ro.product.name=aosp_arm
ro.product.device=generic
ro.product.board=
# ro.product.cpu.abi and ro.product.cpu.abi2 are obsolete,
# use ro.product.cpu.abilist instead.
ro.product.cpu.abi=armeabi-v7a
ro.product.cpu.abi2=armeabi
ro.product.cpu.abilist=armeabi-v7a,armeabi
ro.product.cpu.abilist32=armeabi-v7a,armeabi
ro.product.cpu.abilist64=
ro.product.manufacturer=unknown
ro.product.locale=en-US
ro.wifi.channels=
ro.board.platform=
# ro.build.product is obsolete; use ro.product.device
ro.build.product=generic
# Do not try to parse description, fingerprint, or thumbprint
ro.build.description=aosp_arm-eng 7.1.2 N2G47F eng.sam.20180525.204329 
test-keys


ro.build.characteristics=emulator
# end build properties
#
# from build/target/board/generic/system.prop
#
#
# system.prop for generic sdk
#

rild.libpath=/system/lib/libreference-ril.so
rild.libargs=-d /dev/ttyS0

#
# ADDITIONAL_BUILD_PROPERTIES
#
keyguard.no_require_sim=true
ro.com.android.dataroaming=true
ro.config.ringtone=Ring_Synth_04.ogg
ro.config.notification_sound=pixiedust.ogg
ro.carrier=unknown
ro.bootloader=PWN
ro.bootmode=PWN
ro.hardware=PWN
ro.kernel.qemu=PWN
ro.product.device=PWN
ro.product.model=PWN
ro.product.name=PWN
ro.config.alarm_alert=Alarm_Classic.ogg
ro.ril.hsxpa=1
ro.ril.gprsclass=10
ro.adb.qemud=1
persist.sys.dalvik.vm.lib.2=libart.so
dalvik.vm.isa.arm.variant=generic
dalvik.vm.isa.arm.features=default
ro.kernel.android.checkjni=1
dalvik.vm.lockprof.threshold=500
dalvik.vm.image-dex2oat-filter=verify-at-runtime
net.bt.name=Android
dalvik.vm.stack-trace-file=/data/anr/traces.txt

Clearly, I overwrite the properties. But when I tried getprop in abd shell the output is this:

[ro.product.device]: [generic]
[ro.product.locale]: [en-US]
[ro.product.manufacturer]: [unknown]
[ro.product.model]: [AOSP on ARM Emulator]
[ro.product.name]: [aosp_arm]

[ro.bootloader]: [unknown]
[ro.bootmode]: [unknown]

I only list a few here but we can see that none of those properties changed. This is weird. Since init should read from build.prop when it starts. Someone told me to recompile the whole system instead of only compile the sdk. I just compiled the whole system but it failed again. The same problem here. I am using nougat 7.1.2_r3. Any help?


Solution

  • If you search the aosp build directory for some of these properties you will see the are set by makefile variables. For example in build/make/tools/buildinfo.sh you can see the line:

    echo "ro.product.model=$PRODUCT_MODEL"
    

    How it works is a little more complex but the point is that you need to set PRODUCT_MODEL in your <device>.mk file like Google suggests in their documentation here: https://source.android.com/setup/develop/new-device