-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea1b684
commit fd53eab
Showing
5 changed files
with
79 additions
and
8 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
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
67 changes: 67 additions & 0 deletions
67
app/src/main/java/akhil/alltrans/BackupSharedPreferences.java
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,67 @@ | ||
/* | ||
* Copyright 2017 Akhil Kedia | ||
* This file is part of AllTrans. | ||
* | ||
* AllTrans 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 | ||
* (at your option) any later version. | ||
* | ||
* AllTrans 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 AllTrans. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package akhil.alltrans; | ||
|
||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
import android.os.Environment; | ||
import android.widget.Toast; | ||
|
||
import java.io.DataOutputStream; | ||
|
||
|
||
public class BackupSharedPreferences { | ||
public static void backupSharedPreferences(Context context) { | ||
@SuppressLint("SdCardPath") | ||
String sharedPath = "/data/data/akhil.alltrans/shared_prefs/"; | ||
String externalPath = Environment.getExternalStorageDirectory().getAbsolutePath(); | ||
if (!isExternalStorageWritable()) { | ||
return; | ||
} | ||
|
||
try { | ||
Process su = Runtime.getRuntime().exec("su"); | ||
DataOutputStream outputStream = new DataOutputStream(su.getOutputStream()); | ||
utils.debugLog("cp -R" + " " + sharedPath + " " + externalPath + "/AllTransBackup/" + "\n"); | ||
outputStream.writeBytes("cp -R" + " " + sharedPath + " " + externalPath + "/AllTransBackup/" + "\n"); | ||
outputStream.writeBytes("exit\n"); | ||
outputStream.flush(); | ||
outputStream.close(); | ||
su.waitFor(); | ||
|
||
CharSequence text = context.getString(R.string.backup_pref_success); | ||
int duration = Toast.LENGTH_SHORT; | ||
Toast toast = Toast.makeText(context, text, duration); | ||
toast.show(); | ||
} catch (Exception e) { | ||
CharSequence text = context.getString(R.string.backup_pref_error); | ||
int duration = Toast.LENGTH_SHORT; | ||
Toast toast = Toast.makeText(context, text, duration); | ||
toast.show(); | ||
} | ||
} | ||
|
||
/* Checks if external storage is available for read and write */ | ||
private static boolean isExternalStorageWritable() { | ||
String state = Environment.getExternalStorageState(); | ||
return Environment.MEDIA_MOUNTED.equals(state); | ||
} | ||
} |
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