Created
July 17, 2024 17:16
-
-
Save Hesamedin/1c3df93392c7c743ffb2b7192e464eb0 to your computer and use it in GitHub Desktop.
This is a helper script to pull cached files on the device (or Emulator). Android 13 and above doesn't let us see the cached files from the Device Explorer. So, this script help us to pull them and look at it whenever needed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#################################################################################################### | |
# This is a helper script to pull cached files on the device (or Emulator). | |
# Android 13 and above doesn't let us see the cached files from the Device Explorer. So, this | |
# script help us to pull them and look at it whenever needed. | |
#################################################################################################### | |
# Download the files of the app ($1: package name) | |
# and store it under the provided path ($2) | |
pullAllFilesUnderThePath() { | |
echo "Params passed to this function: PackageName: $1, ToBeSavedPath: $2" | |
app_package_name="$1" | |
dirname="$2" | |
mkdir -p -- "$dirname" | |
source_file="${dirname}paths.txt" | |
# List the name of the files and save it into the source_file | |
adb shell "run-as $app_package_name ls /data/user/0/$app_package_name/files" | tr -d '\r' > "$source_file" | |
# Using read array to read the file into an array | |
IFS=$'\n' read -d '' -r -a lines < "$source_file" | |
for line in "${lines[@]}"; do | |
echo "Processing line: '$line'" | |
temp_destination="$dirname$line" | |
echo "Destination path: '$temp_destination'" | |
# Debugging: Check if the file exists | |
echo "Checking existence of: /data/user/0/$app_package_name/files/$line" | |
adb shell "run-as $app_package_name ls /data/user/0/$app_package_name/files/$line" | |
if [ $? -ne 0 ]; then | |
echo "File not found: $line" | |
continue | |
fi | |
# Attempt to copy the file | |
echo "Copying file: /data/user/0/$app_package_name/files/$line to $temp_destination" | |
adb shell "run-as $app_package_name cat /data/user/0/$app_package_name/files/$line" > "$temp_destination" 2>/dev/null | |
if [ $? -eq 0 ]; then | |
echo "Copied: $line to $temp_destination" | |
else | |
echo "Failed to copy: $line" | |
fi | |
echo "Done processing: $line" | |
sleep 1 # Adding a small delay | |
done | |
} | |
app_package_name="the.package.name" | |
dirname=".avx/files/" | |
pullAllFilesUnderThePath "$app_package_name" "$dirname" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My app stores files under
/data/user/0/$app_package_name/files
. These are usually JSON files that my app downloads from the back-end.However, this is not the App private space for saving files like shared preferences. I have created another copy of this function and replaced
/data/user/0/$app_package_name/files
with/data/data/$app_package_name/shared_prefs
.