0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-19 19:42:17 +02:00
Anki-Android/tools/storage/set_scoped_storage.sh
Arthur Milchior 613f6597c8 ensure scripts prints escaped character
On my desktop, running `./tools/storage/set_scopde_storage.sh` led to

> Alienware% ./tools/storage/set_scoped_storage.sh
> First argument missing.
> \nPossible arguments:
> limited\t\tEquivalent to a fresh install. /AnkiDroid/ is inaccessible
> full\t\tEquivalent to an upgrade from targetSdkVersion 29 to 30. /AnkiDroid/ is accessible\n

Adding `-e` ensures the characters are printed as expected.
2023-04-15 14:38:14 -03:00

43 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
# enable/disable scoped storage: ./set_scoped_storage.sh [limited/full]
function help() {
echo -e "\nPossible arguments:"
echo -e "limited\t\tEquivalent to a fresh install. /AnkiDroid/ is inaccessible"
echo -e "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
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'"
help
fi
# future extension: have an argument trigger the 'permission revoked' state by changing 'deckPath'
# while storage is 'limited'