[Android] don't load forge.profile.properties when the user is using the obb directory

- until google permits unrestricted access outside the app-specific directory on certain apps via flag, the option to use obb as entrypoint is required since accessing outside the scoped storage is really not recommended (https://issuetracker.google.com/issues?q=scoped%20storage%20slow).
This commit is contained in:
Anthony Calosa
2021-04-27 21:04:51 +08:00
parent 045d7bb5ae
commit 77e56e8da9
4 changed files with 25 additions and 22 deletions

View File

@@ -88,7 +88,7 @@ public class Forge implements ApplicationListener {
if (GuiBase.getInterface() == null) {
clipboard = clipboard0;
deviceAdapter = deviceAdapter0;
GuiBase.setUsingAppDirectory(assetDir0.contains("forge.app"));
GuiBase.setUsingAppDirectory(assetDir0.contains("forge.app")); //obb directory on android uses the package name as entrypoint
GuiBase.setInterface(new GuiMobile(assetDir0));
GuiBase.enablePropertyConfig(value);
isPortraitMode = androidOrientation;

View File

@@ -5,6 +5,7 @@ import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import forge.gui.GuiBase;
import org.apache.commons.lang3.StringUtils;
import com.badlogic.gdx.utils.Align;
@@ -133,26 +134,28 @@ public class FilesPage extends TabPage<SettingsScreen> {
ForgeProfileProperties.setDecksDir(newDir);
}
};
lstItems.addItem(new StorageOption(localizer.getMessage("lblDataLocation"), ForgeProfileProperties.getUserDir()) {
@Override
protected void onDirectoryChanged(String newDir) {
ForgeProfileProperties.setUserDir(newDir);
if (!GuiBase.isUsingAppDirectory()) {
lstItems.addItem(new StorageOption(localizer.getMessage("lblDataLocation"), ForgeProfileProperties.getUserDir()) {
@Override
protected void onDirectoryChanged(String newDir) {
ForgeProfileProperties.setUserDir(newDir);
//ensure decks option is updated if needed
decksOption.updateDir(ForgeProfileProperties.getDecksDir());
}
}, 1);
lstItems.addItem(new StorageOption(localizer.getMessage("lblImageCacheLocation"), ForgeProfileProperties.getCacheDir()) {
@Override
protected void onDirectoryChanged(String newDir) {
ForgeProfileProperties.setCacheDir(newDir);
//ensure decks option is updated if needed
decksOption.updateDir(ForgeProfileProperties.getDecksDir());
}
}, 1);
lstItems.addItem(new StorageOption(localizer.getMessage("lblImageCacheLocation"), ForgeProfileProperties.getCacheDir()) {
@Override
protected void onDirectoryChanged(String newDir) {
ForgeProfileProperties.setCacheDir(newDir);
//ensure card pics option is updated if needed
cardPicsOption.updateDir(ForgeProfileProperties.getCardPicsDir());
}
}, 1);
lstItems.addItem(cardPicsOption, 1);
lstItems.addItem(decksOption, 1);
//ensure card pics option is updated if needed
cardPicsOption.updateDir(ForgeProfileProperties.getCardPicsDir());
}
}, 1);
lstItems.addItem(cardPicsOption, 1);
lstItems.addItem(decksOption, 1);
}
}
@Override

View File

@@ -212,7 +212,7 @@ public final class ForgeConstants {
public static final String DECK_BASE_DIR;
public static final String DECK_CONSTRUCTED_DIR;
static {
ForgeProfileProperties.load();
ForgeProfileProperties.load(GuiBase.isUsingAppDirectory());
USER_DIR = ForgeProfileProperties.getUserDir();
CACHE_DIR = ForgeProfileProperties.getCacheDir();
CACHE_CARD_PICS_DIR = ForgeProfileProperties.getCardPicsDir();

View File

@@ -57,11 +57,11 @@ public class ForgeProfileProperties {
//prevent initializing static class
}
public static void load() {
public static void load(boolean isUsingAppDirectory) {
final Properties props = new Properties();
final File propFile = new File(ForgeConstants.PROFILE_FILE);
try {
if (propFile.canRead()) {
if (propFile.canRead() && !isUsingAppDirectory) {
props.load(new FileInputStream(propFile));
}
} catch (final IOException e) {