1*38e8c45fSAndroid Build Coastguard Worker# `dumpstate` development tips 2*38e8c45fSAndroid Build Coastguard Worker 3*38e8c45fSAndroid Build Coastguard Worker## To build `dumpstate` 4*38e8c45fSAndroid Build Coastguard Worker 5*38e8c45fSAndroid Build Coastguard WorkerDo a full build first: 6*38e8c45fSAndroid Build Coastguard Worker 7*38e8c45fSAndroid Build Coastguard Worker``` 8*38e8c45fSAndroid Build Coastguard Workerm -j dumpstate 9*38e8c45fSAndroid Build Coastguard Worker``` 10*38e8c45fSAndroid Build Coastguard Worker 11*38e8c45fSAndroid Build Coastguard WorkerThen incremental ones: 12*38e8c45fSAndroid Build Coastguard Worker 13*38e8c45fSAndroid Build Coastguard Worker``` 14*38e8c45fSAndroid Build Coastguard Workermmm -j frameworks/native/cmds/dumpstate 15*38e8c45fSAndroid Build Coastguard Worker``` 16*38e8c45fSAndroid Build Coastguard Worker 17*38e8c45fSAndroid Build Coastguard WorkerIf you're working on device-specific code, you might need to build them as well. 18*38e8c45fSAndroid Build Coastguard WorkerExample: 19*38e8c45fSAndroid Build Coastguard Worker 20*38e8c45fSAndroid Build Coastguard Worker``` 21*38e8c45fSAndroid Build Coastguard Workermmm -j frameworks/native/cmds/dumpstate device/acme/secret_device/dumpstate/ hardware/interfaces/dumpstate 22*38e8c45fSAndroid Build Coastguard Worker``` 23*38e8c45fSAndroid Build Coastguard Worker 24*38e8c45fSAndroid Build Coastguard Worker## To build, deploy, and take a bugreport 25*38e8c45fSAndroid Build Coastguard Worker 26*38e8c45fSAndroid Build Coastguard Worker``` 27*38e8c45fSAndroid Build Coastguard Workermmm -j frameworks/native/cmds/dumpstate && adb push ${OUT}/system/bin/dumpstate system/bin && adb push ${OUT}/system/lib64/*dumpstate*.so /system/lib64/ && adb shell am bug-report 28*38e8c45fSAndroid Build Coastguard Worker``` 29*38e8c45fSAndroid Build Coastguard Worker 30*38e8c45fSAndroid Build Coastguard WorkerMake sure that the device is remounted before running the above command. * If 31*38e8c45fSAndroid Build Coastguard Workeryou're working with `userdebug` variant, you may need to run the following to 32*38e8c45fSAndroid Build Coastguard Workerremount your device: 33*38e8c45fSAndroid Build Coastguard Worker 34*38e8c45fSAndroid Build Coastguard Worker``` 35*38e8c45fSAndroid Build Coastguard Worker adb root && adb remount -R && adb wait-for-device && adb root && adb remount 36*38e8c45fSAndroid Build Coastguard Worker``` 37*38e8c45fSAndroid Build Coastguard Worker 38*38e8c45fSAndroid Build Coastguard Worker* If you're working with `eng` variant, you may need to run the following to 39*38e8c45fSAndroid Build Coastguard Worker remount your device: 40*38e8c45fSAndroid Build Coastguard Worker 41*38e8c45fSAndroid Build Coastguard Worker ``` 42*38e8c45fSAndroid Build Coastguard Worker adb root && adb remount 43*38e8c45fSAndroid Build Coastguard Worker ``` 44*38e8c45fSAndroid Build Coastguard Worker 45*38e8c45fSAndroid Build Coastguard Worker## To build, deploy, and run unit tests 46*38e8c45fSAndroid Build Coastguard Worker 47*38e8c45fSAndroid Build Coastguard WorkerFirst create `/data/nativetest64`: 48*38e8c45fSAndroid Build Coastguard Worker 49*38e8c45fSAndroid Build Coastguard Worker``` 50*38e8c45fSAndroid Build Coastguard Workeradb shell mkdir /data/nativetest64 51*38e8c45fSAndroid Build Coastguard Worker``` 52*38e8c45fSAndroid Build Coastguard Worker 53*38e8c45fSAndroid Build Coastguard WorkerThen run: 54*38e8c45fSAndroid Build Coastguard Worker 55*38e8c45fSAndroid Build Coastguard Worker``` 56*38e8c45fSAndroid Build Coastguard Workermmm -j frameworks/native/cmds/dumpstate/ && adb push ${OUT}/data/nativetest64/dumpstate_* /data/nativetest64 && adb shell /data/nativetest64/dumpstate_test/dumpstate_test 57*38e8c45fSAndroid Build Coastguard Worker``` 58*38e8c45fSAndroid Build Coastguard Worker 59*38e8c45fSAndroid Build Coastguard WorkerAnd to run just one test (for example, `DumpstateTest.RunCommandNoArgs`): 60*38e8c45fSAndroid Build Coastguard Worker 61*38e8c45fSAndroid Build Coastguard Worker``` 62*38e8c45fSAndroid Build Coastguard Workermmm -j frameworks/native/cmds/dumpstate/ && adb push ${OUT}/data/nativetest64/dumpstate_test* /data/nativetest64 && adb shell /data/nativetest64/dumpstate_test/dumpstate_test --gtest_filter=DumpstateTest.RunCommandNoArgs 63*38e8c45fSAndroid Build Coastguard Worker``` 64*38e8c45fSAndroid Build Coastguard Worker 65*38e8c45fSAndroid Build Coastguard Worker## To take quick bugreports 66*38e8c45fSAndroid Build Coastguard Worker 67*38e8c45fSAndroid Build Coastguard Worker``` 68*38e8c45fSAndroid Build Coastguard Workeradb shell setprop dumpstate.dry_run true 69*38e8c45fSAndroid Build Coastguard Worker``` 70*38e8c45fSAndroid Build Coastguard Worker 71*38e8c45fSAndroid Build Coastguard Worker## To emulate a device with user build 72*38e8c45fSAndroid Build Coastguard Worker 73*38e8c45fSAndroid Build Coastguard Worker``` 74*38e8c45fSAndroid Build Coastguard Workeradb shell setprop dumpstate.unroot true 75*38e8c45fSAndroid Build Coastguard Worker``` 76*38e8c45fSAndroid Build Coastguard Worker 77*38e8c45fSAndroid Build Coastguard Worker## To change the `dumpstate` version 78*38e8c45fSAndroid Build Coastguard Worker 79*38e8c45fSAndroid Build Coastguard Worker``` 80*38e8c45fSAndroid Build Coastguard Workeradb shell setprop dumpstate.version VERSION_NAME 81*38e8c45fSAndroid Build Coastguard Worker``` 82*38e8c45fSAndroid Build Coastguard Worker 83*38e8c45fSAndroid Build Coastguard WorkerExample: 84*38e8c45fSAndroid Build Coastguard Worker 85*38e8c45fSAndroid Build Coastguard Worker``` 86*38e8c45fSAndroid Build Coastguard Workeradb shell setprop dumpstate.version split-dumpsys && adb shell dumpstate -v 87*38e8c45fSAndroid Build Coastguard Worker``` 88*38e8c45fSAndroid Build Coastguard Worker 89*38e8c45fSAndroid Build Coastguard WorkerThen to restore the default version: 90*38e8c45fSAndroid Build Coastguard Worker 91*38e8c45fSAndroid Build Coastguard Worker``` 92*38e8c45fSAndroid Build Coastguard Workeradb shell setprop dumpstate.version default 93*38e8c45fSAndroid Build Coastguard Worker``` 94*38e8c45fSAndroid Build Coastguard Worker 95*38e8c45fSAndroid Build Coastguard Worker## To set Bugreport API workflow for bugreport 96*38e8c45fSAndroid Build Coastguard Worker 97*38e8c45fSAndroid Build Coastguard Worker``` 98*38e8c45fSAndroid Build Coastguard Workeradb shell setprop settings_call_bugreport_api true 99*38e8c45fSAndroid Build Coastguard Worker``` 100*38e8c45fSAndroid Build Coastguard Worker 101*38e8c45fSAndroid Build Coastguard Worker## Code style and formatting 102*38e8c45fSAndroid Build Coastguard Worker 103*38e8c45fSAndroid Build Coastguard WorkerUse the style defined at the 104*38e8c45fSAndroid Build Coastguard Worker[Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html) and 105*38e8c45fSAndroid Build Coastguard Workermake sure to run the following command prior to `repo upload`: 106*38e8c45fSAndroid Build Coastguard Worker 107*38e8c45fSAndroid Build Coastguard Worker``` 108*38e8c45fSAndroid Build Coastguard Workergit clang-format --style=file HEAD~ 109*38e8c45fSAndroid Build Coastguard Worker``` 110*38e8c45fSAndroid Build Coastguard Worker 111*38e8c45fSAndroid Build Coastguard Worker## Useful Bash tricks 112*38e8c45fSAndroid Build Coastguard Worker 113*38e8c45fSAndroid Build Coastguard Worker``` 114*38e8c45fSAndroid Build Coastguard Workerexport BR_DIR=/bugreports 115*38e8c45fSAndroid Build Coastguard Worker 116*38e8c45fSAndroid Build Coastguard Workeralias br='adb shell cmd activity bug-report' 117*38e8c45fSAndroid Build Coastguard Workeralias ls_bugs='adb shell ls -l ${BR_DIR}/' 118*38e8c45fSAndroid Build Coastguard Worker 119*38e8c45fSAndroid Build Coastguard Workerunzip_bug() { 120*38e8c45fSAndroid Build Coastguard Worker adb pull ${BR_DIR}/$1 && emacs $1 && mv $1 /tmp 121*38e8c45fSAndroid Build Coastguard Worker} 122*38e8c45fSAndroid Build Coastguard Worker 123*38e8c45fSAndroid Build Coastguard Workerless_bug() { 124*38e8c45fSAndroid Build Coastguard Worker adb pull ${BR_DIR}/$1 && less $1 && mv $1 /tmp 125*38e8c45fSAndroid Build Coastguard Worker} 126*38e8c45fSAndroid Build Coastguard Worker 127*38e8c45fSAndroid Build Coastguard Workerrm_bugs() { 128*38e8c45fSAndroid Build Coastguard Worker if [ -z "${BR_DIR}" ] ; then echo "Variable BR_DIR not set"; else adb shell rm -rf ${BR_DIR}/*; fi 129*38e8c45fSAndroid Build Coastguard Worker} 130*38e8c45fSAndroid Build Coastguard Worker 131*38e8c45fSAndroid Build Coastguard Worker``` 132