Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tool: enable/disable scoped storage #13397

Merged
merged 1 commit into from
Mar 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions tools/storage/set_scoped_storage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#/bin/bash
# enable/disable scoped storage: ./set_scoped_storage.sh [limited/full]


function help() {
echo "\nPossible arguments:"
echo "limited\t\tEquivalent to a fresh install. /AnkiDroid/ is inaccessible"
echo "full\t\tEquivalent to an upgrade from targetSdkVersion 29 to 30. /AnkiDroid/ is accessible\n"
}

# This should be run when a single AOSP emulator is open.
# Errors are suppressed by default. Remove > /dev/null
if [ "$1" = "full" ]; then
adb shell pm grant com.ichi2.anki.debug android.permission.READ_EXTERNAL_STORAGE
BrayanDSO marked this conversation as resolved.
Show resolved Hide resolved
adb shell pm grant com.ichi2.anki.debug android.permission.WRITE_EXTERNAL_STORAGE
adb shell am compat disable FORCE_ENABLE_SCOPED_STORAGE com.ichi2.anki.debug > /dev/null
adb shell am compat disable DEFAULT_SCOPED_STORAGE com.ichi2.anki.debug > /dev/null # fails on Play store
if [ $? == '0' ]; then
echo "scoped storage disabled: preserving storage access"
else
echo "something went wrong: edit script to display errors"
fi
elif [ "$1" = "limited" ]; then
adb shell pm revoke com.ichi2.anki.debug android.permission.READ_EXTERNAL_STORAGE
adb shell pm revoke com.ichi2.anki.debug android.permission.WRITE_EXTERNAL_STORAGE
adb shell am compat enable FORCE_ENABLE_SCOPED_STORAGE com.ichi2.anki.debug > /dev/null
adb shell am compat enable DEFAULT_SCOPED_STORAGE com.ichi2.anki.debug > /dev/null
if [ $? == '0' ]; then
echo "scoped storage enabled: storage access disabled"
else
echo "something went wrong: edit script to display errors"
fi
elif [ "$1" = "" ]; then
echo "First argument missing."
help
else
echo "unknown argument: '$1'. Valid values: 'limited', 'full'"
david-allison marked this conversation as resolved.
Show resolved Hide resolved
help
fi


# future extension: have an argument trigger the 'permission revoked' state by changing 'deckPath'
# while storage is 'limited'