-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from SecUSo/features/backup-integration
Features/backup integration
- Loading branch information
Showing
15 changed files
with
344 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "libs/privacy-friendly-backup-api"] | ||
path = libs/privacy-friendly-backup-api | ||
url = https://github.com/SecUSo/privacy-friendly-backup-api.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
app/src/main/java/org/secuso/privacyfriendlysudoku/PFSudoku.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
This file is part of Privacy Friendly Sudoku. | ||
Privacy Friendly Sudoku is free software: | ||
you can redistribute it and/or modify it under the terms of the | ||
GNU General Public License as published by the Free Software Foundation, | ||
either version 3 of the License, or any later version. | ||
Privacy Friendly Sudoku is distributed in the hope | ||
that it will be useful, but WITHOUT ANY WARRANTY; without even | ||
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
See the GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with Privacy Friendly Sudoku. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.secuso.privacyfriendlysudoku | ||
|
||
import android.app.Application | ||
import android.app.NotificationChannel | ||
import android.app.NotificationManager | ||
import android.os.Build | ||
import android.util.Log | ||
import androidx.appcompat.app.AppCompatDelegate | ||
import androidx.work.Configuration | ||
import org.secuso.privacyfriendlysudoku.backup.BackupCreator | ||
import org.secuso.privacyfriendlysudoku.backup.BackupRestorer | ||
import org.secuso.privacyfriendlybackup.api.pfa.BackupManager | ||
|
||
class PFSudoku : Application(), Configuration.Provider { | ||
override fun onCreate() { | ||
BackupManager.backupCreator = BackupCreator() | ||
BackupManager.backupRestorer = BackupRestorer() | ||
super.onCreate() | ||
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true) | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
// channels | ||
val channel = NotificationChannel(CHANNEL_ID, "Default", NotificationManager.IMPORTANCE_LOW) | ||
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager | ||
notificationManager?.createNotificationChannel(channel) | ||
} | ||
} | ||
|
||
override fun getWorkManagerConfiguration(): Configuration { | ||
return Configuration.Builder().setMinimumLoggingLevel(Log.INFO).build() | ||
} | ||
|
||
companion object { | ||
const val CHANNEL_ID = "sudoku.0" | ||
} | ||
} |
48 changes: 0 additions & 48 deletions
48
app/src/main/java/org/secuso/privacyfriendlysudoku/SudokuApp.java
This file was deleted.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
app/src/main/java/org/secuso/privacyfriendlysudoku/backup/BackupCreator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.secuso.privacyfriendlysudoku.backup | ||
|
||
|
||
import android.content.Context | ||
import android.preference.PreferenceManager | ||
import android.util.JsonWriter | ||
import android.util.Log | ||
import org.secuso.privacyfriendlybackup.api.backup.DatabaseUtil.getSupportSQLiteOpenHelper | ||
import org.secuso.privacyfriendlybackup.api.backup.DatabaseUtil.writeDatabase | ||
import org.secuso.privacyfriendlybackup.api.backup.FileUtil | ||
import org.secuso.privacyfriendlybackup.api.backup.PreferenceUtil.writePreferences | ||
import org.secuso.privacyfriendlybackup.api.pfa.IBackupCreator | ||
import org.secuso.privacyfriendlysudoku.controller.database.DatabaseHelper | ||
import java.io.File | ||
import java.io.OutputStream | ||
import java.io.OutputStreamWriter | ||
import java.util.Arrays | ||
|
||
class BackupCreator : IBackupCreator { | ||
override fun writeBackup(context: Context, outputStream: OutputStream): Boolean { | ||
Log.d(TAG, "createBackup() started") | ||
val outputStreamWriter = OutputStreamWriter(outputStream, Charsets.UTF_8) | ||
val writer = JsonWriter(outputStreamWriter) | ||
writer.setIndent("") | ||
|
||
try { | ||
writer.beginObject() | ||
|
||
Log.d(TAG, "Writing database") | ||
writer.name("database") | ||
|
||
val database = getSupportSQLiteOpenHelper(context, DatabaseHelper.DATABASE_NAME).readableDatabase | ||
|
||
writeDatabase(writer, database) | ||
database.close() | ||
|
||
Log.d(TAG, "Writing preferences") | ||
writer.name("preferences") | ||
|
||
val pref = PreferenceManager.getDefaultSharedPreferences(context.applicationContext) | ||
writePreferences(writer, pref) | ||
|
||
Log.d(TAG, "Writing files") | ||
writer.name("files") | ||
writer.beginObject() | ||
for (path in listOf("stats", "saves", "level")) { | ||
val dir = context.getDir(path, 0) | ||
Log.d(TAG,"writing dir ${dir.path}") | ||
writer.name(path) | ||
FileUtil.writePath(writer, dir, false) | ||
} | ||
writer.endObject() | ||
|
||
writer.endObject() | ||
writer.close() | ||
} catch (e: Exception) { | ||
Log.e(TAG, "Error occurred", e) | ||
e.printStackTrace() | ||
return false | ||
} | ||
|
||
Log.d(TAG, "Backup created successfully") | ||
return true | ||
} | ||
|
||
companion object { | ||
const val TAG = "PFABackupCreator" | ||
} | ||
} |
Oops, something went wrong.