From f10fe23f005755422913adcfd323e5c5b3453541 Mon Sep 17 00:00:00 2001 From: kardelio Date: Wed, 17 Mar 2021 14:51:21 +0100 Subject: [PATCH] Added start of View Hierarchy work with -v flag --- easy-dumpsys | 106 ++++++++++++++++++++++++++++++++++++--------------- notes | 47 +++++++++++++++++++++++ 2 files changed, 122 insertions(+), 31 deletions(-) create mode 100644 notes diff --git a/easy-dumpsys b/easy-dumpsys index 8c73790..953f127 100755 --- a/easy-dumpsys +++ b/easy-dumpsys @@ -18,6 +18,8 @@ mapFile=".ds_temp_map_file_$timestamp" keepFile=false useSpecificFile="" +argsCount=$# + #TODO: # Turns out that applications have fragments like this: # ······#1:·RestaurantListContent{2602624·#1·id=0x7f0a00f1·RestaurantListContent}$ @@ -34,6 +36,71 @@ useSpecificFile="" # static final int RESUMED = 5; // Created started and resumed. #What is state 7? +function selectAndPreparePackage(){ + package=$1 + if [ $argsCount -eq 0 ] && [ -z "$useSpecificFile" ]; then + fzf_installed=$(which fzf) + if [[ -z ${fzf_installed} ]]; then + echo "FZF is NOT installed so you can not use the interactive package picker" + echo "Install FZF to enable this feature" + exit 1 + else + packToUse=$(adb shell pm list package -3 | fzf | cut -d':' -f2) + echo "Using package: $packToUse" + package="$packToUse" + if [[ -z "$package" ]]; then + echo "No package provided!" + exit 1 + fi + fi + fi + + # The all important adb dumpsys command + if [[ -z "$useSpecificFile" ]]; then + adb shell dumpsys activity "$package" > "$dsFileName" + else + cat "$useSpecificFile" > "$dsFileName" + fi + + sed -i '' '/Added\ Fragments\:/,/FragmentManager\ misc\ state\:/d' "$dsFileName" + sed -i '' '/Child\ FragmentManager/d' "$dsFileName" +} + +function cleanUpDSFile(){ + if [[ "$keepFile" = false ]]; then + rm "$dsFileName" + fi +} + +function getIndentAmount(){ + local indent=$(echo "$1" | sed 's/[a-zA-Z0-9].*//g' | wc -c | sed 's/[[:space:]]//g') + indent=$((indent - 1)) + echo "$indent" +} + +function printElement(){ + local class=$(echo "$1" | cut -d{ -f1) + local id=$(echo "$1" | awk '{print $NF}' | sed 's/}//g') + local status=$(echo "$1" | awk '{print $2}') + #V = visible, I = invisible, G = gone + local vis=$(echo "${status:0:1}") + echo "$class - $id - $vis" +} + +function viewHierarchy(){ + lineIter=1 + while IFS= read -r line + do + currentIndent=$(getIndentAmount "$line") + nextLine=$(sed -n $((lineIter + 1))p vh-ex.txt) + nextIndent=$(getIndentAmount "$nextLine") + if [[ "$nextIndent" -le "$currentIndent" ]]; then + printElement "$line" + fi + lineIter=$((lineIter + 1)) + done < "$1" #File to read from +} + while getopts khf:v flag do case "${flag}" in @@ -42,7 +109,12 @@ do exit 0 ;; v) - echo "Easy-Dumpsys Version: $(cat "$versionFile")" + shift 1 + selectAndPreparePackage "$1" + sed -i '' '1,/^[[:space:]]*View\ H/d;/^[[:space:]]*Looper/,$d' "$dsFileName" + viewHierarchy "$dsFileName" + cleanUpDSFile + #echo "Easy-Dumpsys Version: $(cat "$versionFile")" exit 0 ;; k) @@ -59,33 +131,7 @@ do esac done -package=$1 -if [ $# -eq 0 ] && [ -z "$useSpecificFile" ]; then - fzf_installed=$(which fzf) - if [[ -z ${fzf_installed} ]]; then - echo "FZF is NOT installed so you can not use the interactive package picker" - echo "Install FZF to enable this feature" - exit 1 - else - packToUse=$(adb shell pm list package -3 | fzf | cut -d':' -f2) - echo "Using package: $packToUse" - package="$packToUse" - if [[ -z "$package" ]]; then - echo "No package provided!" - exit 1 - fi - fi -fi - -# The all important adb dumpsys command -if [[ -z "$useSpecificFile" ]]; then - adb shell dumpsys activity "$package" > "$dsFileName" -else - cat "$useSpecificFile" > "$dsFileName" -fi - -sed -i '' '/Added\ Fragments\:/,/FragmentManager\ misc\ state\:/d' "$dsFileName" -sed -i '' '/Child\ FragmentManager/d' "$dsFileName" +selectAndPreparePackage "$1" lineIterator=0 while IFS= read -r line @@ -261,8 +307,6 @@ do done < "$mapFile" printf "\n" -if [[ "$keepFile" = false ]]; then - rm "$dsFileName" -fi +cleanUpDSFile rm "$simpleFile" rm "$mapFile" diff --git a/notes b/notes new file mode 100644 index 0000000..201005e --- /dev/null +++ b/notes @@ -0,0 +1,47 @@ +switch (mViewFlags&VISIBILITY_MASK) { + case VISIBLE: out.append('V'); break; + case INVISIBLE: out.append('I'); break; + case GONE: out.append('G'); break; + default: out.append('.'); break; + } + out.append((mViewFlags & FOCUSABLE) == FOCUSABLE ? 'F' : '.'); + out.append((mViewFlags&ENABLED_MASK) == ENABLED ? 'E' : '.'); + out.append((mViewFlags&DRAW_MASK) == WILL_NOT_DRAW ? '.' : 'D'); + out.append((mViewFlags&SCROLLBARS_HORIZONTAL) != 0 ? 'H' : '.'); + out.append((mViewFlags&SCROLLBARS_VERTICAL) != 0 ? 'V' : '.'); + out.append((mViewFlags&CLICKABLE) != 0 ? 'C' : '.'); + out.append((mViewFlags&LONG_CLICKABLE) != 0 ? 'L' : '.'); + out.append((mViewFlags&CONTEXT_CLICKABLE) != 0 ? 'X' : '.'); + out.append(' '); + out.append((mPrivateFlags&PFLAG_IS_ROOT_NAMESPACE) != 0 ? 'R' : '.'); + out.append((mPrivateFlags&PFLAG_FOCUSED) != 0 ? 'F' : '.'); + out.append((mPrivateFlags&PFLAG_SELECTED) != 0 ? 'S' : '.'); + if ((mPrivateFlags&PFLAG_PREPRESSED) != 0) { + out.append('p'); + } else { + out.append((mPrivateFlags&PFLAG_PRESSED) != 0 ? 'P' : '.'); + } + out.append((mPrivateFlags&PFLAG_HOVERED) != 0 ? 'H' : '.'); + out.append((mPrivateFlags&PFLAG_ACTIVATED) != 0 ? 'A' : '.'); + out.append((mPrivateFlags&PFLAG_INVALIDATED) != 0 ? 'I' : '.'); + out.append((mPrivateFlags&PFLAG_DIRTY_MASK) != 0 ? 'D' : '.'); + + +https://android.googlesource.com/platform/frameworks/base/+/refs/heads/android11-release/core/java/android/view/View.java#6442 + + + + +(4) + View Hierarchy: + + Looper (main, tid 2) {70b234c} +(4) + + +Just child nodes + +go line by line +if next line is equal in indent +or less than then this is a child node +