Compare commits
2 Commits
d803d57af1
...
e33915b578
Author | SHA1 | Date | |
---|---|---|---|
e33915b578 | |||
bdfded960c |
@ -11,8 +11,8 @@ android {
|
|||||||
compileSdkVersion 29
|
compileSdkVersion 29
|
||||||
buildToolsVersion '29.0.2'
|
buildToolsVersion '29.0.2'
|
||||||
useLibrary 'org.apache.http.legacy'
|
useLibrary 'org.apache.http.legacy'
|
||||||
versionCode 98
|
versionCode 99
|
||||||
versionName "1.6.22"
|
versionName "1.6.23"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
@ -21,9 +21,6 @@ import android.provider.MediaStore;
|
|||||||
import android.provider.Settings.Secure;
|
import android.provider.Settings.Secure;
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import androidx.core.app.NotificationCompat;
|
|
||||||
|
|
||||||
import com.jens.automation2.location.LocationProvider;
|
import com.jens.automation2.location.LocationProvider;
|
||||||
import com.jens.automation2.receivers.PhoneStatusListener;
|
import com.jens.automation2.receivers.PhoneStatusListener;
|
||||||
@ -47,11 +44,14 @@ import org.xml.sax.SAXException;
|
|||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.lang.Thread.UncaughtExceptionHandler;
|
import java.lang.Thread.UncaughtExceptionHandler;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
@ -81,6 +81,8 @@ import javax.xml.parsers.DocumentBuilder;
|
|||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
|
import androidx.core.app.NotificationCompat;
|
||||||
|
|
||||||
import static com.jens.automation2.AutomationService.NOTIFICATION_CHANNEL_ID;
|
import static com.jens.automation2.AutomationService.NOTIFICATION_CHANNEL_ID;
|
||||||
import static com.jens.automation2.AutomationService.channelName;
|
import static com.jens.automation2.AutomationService.channelName;
|
||||||
|
|
||||||
@ -312,17 +314,19 @@ public class Miscellaneous extends Service
|
|||||||
public static String getWriteableFolder()
|
public static String getWriteableFolder()
|
||||||
{
|
{
|
||||||
if(writeableFolderStringCache == null)
|
if(writeableFolderStringCache == null)
|
||||||
{
|
|
||||||
if(!ActivityPermissions.havePermission(ActivityPermissions.writeExternalStoragePermissionName, Miscellaneous.getAnyContext()))
|
|
||||||
{
|
{
|
||||||
// Use the app-specific folder as new default.
|
// Use the app-specific folder as new default.
|
||||||
|
|
||||||
writeableFolderStringCache = Miscellaneous.getAnyContext().getFilesDir().getAbsolutePath();
|
writeableFolderStringCache = Miscellaneous.getAnyContext().getFilesDir().getAbsolutePath();
|
||||||
return writeableFolderStringCache;
|
|
||||||
}
|
File newConfigFile = new File(writeableFolderStringCache + "/" + XmlFileInterface.settingsFileName);
|
||||||
else
|
|
||||||
|
migration:
|
||||||
|
if (!newConfigFile.exists())
|
||||||
{
|
{
|
||||||
//TODO: We have the storage permission, probably because it's an old installation. Files should be migrated to app-specific folder.
|
if (ActivityPermissions.havePermission(ActivityPermissions.writeExternalStoragePermissionName, Miscellaneous.getAnyContext()))
|
||||||
|
{
|
||||||
|
// We have the storage permission, probably because it's an old installation. Files should be migrated to app-specific folder.
|
||||||
|
|
||||||
String testPath = null;
|
String testPath = null;
|
||||||
File folder = null;
|
File folder = null;
|
||||||
|
|
||||||
@ -338,29 +342,46 @@ public class Miscellaneous extends Service
|
|||||||
|
|
||||||
for (String f : foldersToTestArray)
|
for (String f : foldersToTestArray)
|
||||||
{
|
{
|
||||||
if (testFolder(f))
|
// if (testFolder(f))
|
||||||
{
|
// {
|
||||||
String pathToUse = f + "/" + Settings.folderName;
|
String pathToUse = f + "/" + Settings.folderName;
|
||||||
Miscellaneous.logEvent("i", "Path", "Using " + pathToUse + " to store settings and log.", 2);
|
|
||||||
// Toast.makeText(getAnyContext(), "Using " + pathToUse + " to store settings and log.", Toast.LENGTH_LONG).show();
|
// Toast.makeText(getAnyContext(), "Using " + pathToUse + " to store settings and log.", Toast.LENGTH_LONG).show();
|
||||||
return pathToUse;
|
// Migrate existing files
|
||||||
|
File oldDirectory = new File(pathToUse);
|
||||||
|
File newDirectory = new File(writeableFolderStringCache);
|
||||||
|
File oldConfigFilePath = new File(pathToUse + "/" + XmlFileInterface.settingsFileName);
|
||||||
|
if (oldConfigFilePath.exists() && oldConfigFilePath.canWrite())
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("i", "Path", "Found old path " + pathToUse + " for settings and logs. Migrating old files to new directory.", 2);
|
||||||
|
|
||||||
|
for (File fileToBeMoved : oldDirectory.listFiles())
|
||||||
|
{
|
||||||
|
File dstFile = new File(writeableFolderStringCache + "/" + fileToBeMoved.getName());
|
||||||
|
|
||||||
|
/*
|
||||||
|
For some stupid reason Android's file.moveTo can't move files between
|
||||||
|
mount points. That's why we have to copy it and delete the src if successful.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if(copyFileUsingStream(fileToBeMoved, dstFile))
|
||||||
|
fileToBeMoved.delete();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
Miscellaneous.logEvent("e", "getWritableFolder", folder.getAbsolutePath() + " does not exist and could not be created.", 3);
|
String message = String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.filesHaveBeenMovedTo), newDirectory.getAbsolutePath());
|
||||||
|
Miscellaneous.writeStringToFile(oldDirectory.getAbsolutePath() + "/readme.txt", message);
|
||||||
|
break migration;
|
||||||
|
}
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
} catch (Exception e)
|
} catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.w("getWritableFolder", folder + " not writable.");
|
Log.w("getWritableFolder", folder + " not writable.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// do not change to logEvent() - we can't write
|
|
||||||
Toast.makeText(getAnyContext(), "No writable folder could be found.", Toast.LENGTH_LONG).show();
|
|
||||||
Log.e("getWritableFolder", "No writable folder could be found.");
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
|
||||||
return writeableFolderStringCache;
|
return writeableFolderStringCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1047,4 +1068,32 @@ public class Miscellaneous extends Service
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean copyFileUsingStream(File source, File dest) throws IOException
|
||||||
|
{
|
||||||
|
boolean returnValue = false;
|
||||||
|
|
||||||
|
InputStream is = null;
|
||||||
|
OutputStream os = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
is = new FileInputStream(source);
|
||||||
|
os = new FileOutputStream(dest);
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int length;
|
||||||
|
while ((length = is.read(buffer)) > 0)
|
||||||
|
{
|
||||||
|
os.write(buffer, 0, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
returnValue = true;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
is.close();
|
||||||
|
os.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
}
|
}
|
@ -25,7 +25,8 @@ import java.util.Collections;
|
|||||||
|
|
||||||
public class XmlFileInterface
|
public class XmlFileInterface
|
||||||
{
|
{
|
||||||
public static File settingsFile = new File(Miscellaneous.getWriteableFolder() + "/Automation_settings.xml");
|
public static String settingsFileName = "Automation_settings.xml";
|
||||||
|
public static File settingsFile = new File(Miscellaneous.getWriteableFolder() + "/" + settingsFileName);
|
||||||
public static Context context;
|
public static Context context;
|
||||||
|
|
||||||
protected static final String encryptionKey = "Y1vsP12L2S3NkTJbDOR4bQ6i02hsoo";
|
protected static final String encryptionKey = "Y1vsP12L2S3NkTJbDOR4bQ6i02hsoo";
|
||||||
|
@ -594,4 +594,5 @@
|
|||||||
<string name="deviceDoesNotHaveBluetooth">Dieses Gerät scheint kein Bluetooth zu haben. Sie können mit der Konfiguration fortfahren, aber es wird vermutlich keinen Effekt haben.</string>
|
<string name="deviceDoesNotHaveBluetooth">Dieses Gerät scheint kein Bluetooth zu haben. Sie können mit der Konfiguration fortfahren, aber es wird vermutlich keinen Effekt haben.</string>
|
||||||
<string name="manageLocations">Orte anlegen oder ändern</string>
|
<string name="manageLocations">Orte anlegen oder ändern</string>
|
||||||
<string name="publishedOn">veröffentlicht am</string>
|
<string name="publishedOn">veröffentlicht am</string>
|
||||||
|
<string name="filesHaveBeenMovedTo">Automation benutzt jetzt ein anderes Verzeichnis, um Ihre Daten zu speichern. Alle Ihre Automation-Dateien wurden hierhin verschoben: \"%s\". Die Berechtigung für den externen Speicher wird nun nicht mehr benötigt; Sie können Sie entfernen. In einer künftigen Version wird sie entfernt werden.</string>
|
||||||
</resources>
|
</resources>
|
@ -605,4 +605,5 @@
|
|||||||
<string name="publishedOn">published on</string>
|
<string name="publishedOn">published on</string>
|
||||||
<string name="displayNewsOnMainScreen">Display application news on main screen</string>
|
<string name="displayNewsOnMainScreen">Display application news on main screen</string>
|
||||||
<string name="displayNewsOnMainScreenDescription">Announcements about this app only, we\'re probably talking about 1-2 per year, not more.</string>
|
<string name="displayNewsOnMainScreenDescription">Announcements about this app only, we\'re probably talking about 1-2 per year, not more.</string>
|
||||||
|
<string name="filesHaveBeenMovedTo">Automation now uses another path to store your files. All your Automation-files have been moved here: \"%s\". The external storage permission is not required anymore; you can revoke it. It will be removed in a future version.</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue
Block a user