Changed settings location to regular data folder. Migration of files in existing installations pending.

This commit is contained in:
Jens 2021-03-07 23:45:47 +01:00
parent f9cf3356e7
commit d803d57af1
8 changed files with 83 additions and 68 deletions

View File

@ -53,11 +53,11 @@ public class ActivityMainPoi extends ActivityGeneric
@Override
public void onClick(View v)
{
if(!ActivityPermissions.havePermission(ActivityPermissions.writeExternalStoragePermissionName, ActivityMainPoi.this))
{
Toast.makeText(ActivityMainPoi.this, getResources().getString(R.string.appRequiresPermissiontoAccessExternalStorage), Toast.LENGTH_LONG).show();
return;
}
// if(!ActivityPermissions.havePermission(ActivityPermissions.writeExternalStoragePermissionName, ActivityMainPoi.this))
// {
// Toast.makeText(ActivityMainPoi.this, getResources().getString(R.string.appRequiresPermissiontoAccessExternalStorage), Toast.LENGTH_LONG).show();
// return;
// }
if(!ActivityPermissions.havePermission(ActivityPermissions.permissionNameLocationCoarse, ActivityMainPoi.this) || !ActivityPermissions.havePermission(ActivityPermissions.permissionNameLocationFine, ActivityMainPoi.this))
{

View File

@ -50,11 +50,11 @@ public class ActivityMainProfiles extends ActivityGeneric
@Override
public void onClick(View v)
{
if(!ActivityPermissions.havePermission(ActivityPermissions.writeExternalStoragePermissionName, ActivityMainProfiles.this))
{
Toast.makeText(ActivityMainProfiles.this, getResources().getString(R.string.appRequiresPermissiontoAccessExternalStorage), Toast.LENGTH_LONG).show();
return;
}
// if(!ActivityPermissions.havePermission(ActivityPermissions.writeExternalStoragePermissionName, ActivityMainProfiles.this))
// {
// Toast.makeText(ActivityMainProfiles.this, getResources().getString(R.string.appRequiresPermissiontoAccessExternalStorage), Toast.LENGTH_LONG).show();
// return;
// }
profileToEdit = null;
Intent manageSpecificProfileIntent = new Intent (ActivityMainProfiles.this, ActivityManageProfile.class);

View File

@ -52,11 +52,11 @@ public class ActivityMainRules extends ActivityGeneric
@Override
public void onClick(View v)
{
if(!ActivityPermissions.havePermission(ActivityPermissions.writeExternalStoragePermissionName, ActivityMainRules.this))
{
Toast.makeText(ActivityMainRules.this, getResources().getString(R.string.appRequiresPermissiontoAccessExternalStorage), Toast.LENGTH_LONG).show();
return;
}
// if(!ActivityPermissions.havePermission(ActivityPermissions.writeExternalStoragePermissionName, ActivityMainRules.this))
// {
// Toast.makeText(ActivityMainRules.this, getResources().getString(R.string.appRequiresPermissiontoAccessExternalStorage), Toast.LENGTH_LONG).show();
// return;
// }
ruleToEdit = null;
Intent startAddRuleIntent = new Intent(ActivityMainRules.this, ActivityManageRule.class);

View File

@ -281,8 +281,8 @@ public class ActivityPermissions extends Activity
addToArrayListUnique("android.permission.RECEIVE_BOOT_COMPLETED", requiredPermissions);
*/
if (!havePermission("android.permission.WRITE_EXTERNAL_STORAGE", workingContext))
addToArrayListUnique("android.permission.WRITE_EXTERNAL_STORAGE", requiredPermissions);
// if (!havePermission(ActivityPermissions.writeExternalStoragePermissionName, workingContext))
// addToArrayListUnique(ActivityPermissions.writeExternalStoragePermissionName, requiredPermissions);
for(Profile profile : Profile.getProfileCollection())
{

View File

@ -106,17 +106,17 @@ public class AutomationService extends Service implements OnInitListener
public boolean checkStartupRequirements(Context context, boolean startAtBoot)
{
if (!ActivityPermissions.havePermission(ActivityPermissions.writeExternalStoragePermissionName, AutomationService.this))
{
/*
Don't have permission to access external storage. This is a show stopper as
the configuration file is stored on external storage.
*/
Miscellaneous.logEvent("e", "Permission", "Don't have permission to access external storage. Will request it now.", 4);
// Toast.makeText(AutomationService.this, getResources().getString(R.string.appRequiresPermissiontoAccessExternalStorage), Toast.LENGTH_LONG).show();
ActivityPermissions.requestSpecificPermission(ActivityPermissions.writeExternalStoragePermissionName);
return false;
}
// if (!ActivityPermissions.havePermission(ActivityPermissions.writeExternalStoragePermissionName, AutomationService.this))
// {
// /*
// Don't have permission to access external storage. This is a show stopper as
// the configuration file is stored on external storage.
// */
// Miscellaneous.logEvent("e", "Permission", "Don't have permission to access external storage. Will request it now.", 4);
//// Toast.makeText(AutomationService.this, getResources().getString(R.string.appRequiresPermissiontoAccessExternalStorage), Toast.LENGTH_LONG).show();
// ActivityPermissions.requestSpecificPermission(ActivityPermissions.writeExternalStoragePermissionName);
// return false;
// }
if(Build.VERSION.SDK_INT >= 28)
{

View File

@ -313,6 +313,16 @@ public class Miscellaneous extends Service
{
if(writeableFolderStringCache == null)
{
if(!ActivityPermissions.havePermission(ActivityPermissions.writeExternalStoragePermissionName, Miscellaneous.getAnyContext()))
{
// Use the app-specific folder as new default.
writeableFolderStringCache = Miscellaneous.getAnyContext().getFilesDir().getAbsolutePath();
return writeableFolderStringCache;
}
else
{
//TODO: We have the storage permission, probably because it's an old installation. Files should be migrated to app-specific folder.
String testPath = null;
File folder = null;
@ -326,7 +336,7 @@ public class Miscellaneous extends Service
"/mnt/sdcard"
};
for(String f : foldersToTestArray)
for (String f : foldersToTestArray)
{
if (testFolder(f))
{
@ -338,8 +348,7 @@ public class Miscellaneous extends Service
else
Miscellaneous.logEvent("e", "getWritableFolder", folder.getAbsolutePath() + " does not exist and could not be created.", 3);
}
}
catch(Exception e)
} catch (Exception e)
{
Log.w("getWritableFolder", folder + " not writable.");
}
@ -350,6 +359,7 @@ public class Miscellaneous extends Service
return null;
}
}
else
return writeableFolderStringCache;
}

View File

@ -107,7 +107,7 @@ public class Settings implements SharedPreferences
protected static final boolean default_privacyLocationing = false;
protected static final int default_startScreen = 0;
protected static final boolean default_executeRulesAndProfilesWithSingleClick = false;
protected static final boolean default_displayNewsOnMainScreen = true;
protected static final boolean default_displayNewsOnMainScreen = false;
protected static final boolean default_lockSoundChanges = false;
protected static final long default_lastNewsPolltime = -1;

View File

@ -343,18 +343,23 @@ public class XmlFileInterface
}
public static void readFile() throws FileNotFoundException
{
if(!ActivityPermissions.havePermission(ActivityPermissions.writeExternalStoragePermissionName, Miscellaneous.getAnyContext()))
{
/*
Don't have permission to access external storage. This is a show stopper as
the configuration file is stored on external storage.
Storage location has been moved to app-specific folder in Android/data
Hence this permission is not requested any more. If it is already granted we assume the files are on /sdcard or similar.
Migration to app-specific folder has yet to be implemented.
*/
Miscellaneous.logEvent("e", "Permission", "Don't have permission to access external storage. Will request it now.", 4);
Toast.makeText(Miscellaneous.getAnyContext(), Miscellaneous.getAnyContext().getResources().getString(R.string.appRequiresPermissiontoAccessExternalStorage), Toast.LENGTH_LONG).show();
ActivityPermissions.requestSpecificPermission(ActivityPermissions.writeExternalStoragePermissionName);
return;
}
// if(!ActivityPermissions.havePermission(ActivityPermissions.writeExternalStoragePermissionName, Miscellaneous.getAnyContext()))
// {
// /*
// Don't have permission to access external storage. This is a show stopper as
// the configuration file is stored on external storage.
// */
// Miscellaneous.logEvent("e", "Permission", "Don't have permission to access external storage. Will request it now.", 4);
// Toast.makeText(Miscellaneous.getAnyContext(), Miscellaneous.getAnyContext().getResources().getString(R.string.appRequiresPermissiontoAccessExternalStorage), Toast.LENGTH_LONG).show();
// ActivityPermissions.requestSpecificPermission(ActivityPermissions.writeExternalStoragePermissionName);
// return;
// }
/*
If we are here it may be that we just got permission to read storage. We need to check for the