[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [orbot/master] Backup/Restore for V3 Working on Legacy Orbots with WRITE_EXTERNAL_STORAGE
commit e4a5d02f3cc3205a6629cb0758d6a9b255be9183
Author: bim <dsnake@xxxxxxxxxxxxxx>
Date: Fri Nov 27 14:19:49 2020 -0500
Backup/Restore for V3 Working on Legacy Orbots with WRITE_EXTERNAL_STORAGE
---
.../ui/hiddenservices/HiddenServicesActivity.java | 2 +-
.../ui/hiddenservices/backup/BackupUtils.java | 12 ++++++++++
.../ui/v3onionservice/OnionServicesActivity.java | 26 ++++++++++++++++++++--
3 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/HiddenServicesActivity.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/HiddenServicesActivity.java
index 7a943093..886bd27d 100644
--- a/app/src/main/java/org/torproject/android/ui/hiddenservices/HiddenServicesActivity.java
+++ b/app/src/main/java/org/torproject/android/ui/hiddenservices/HiddenServicesActivity.java
@@ -120,7 +120,7 @@ public class HiddenServicesActivity extends AppCompatActivity {
new AlertDialog.Builder(this)
.setTitle(R.string.restore_backup)
- .setItems(fileNames, (dialog, which) -> new BackupUtils(HiddenServicesActivity.this).restoreZipBackupV2Legacy(files[which]))
+ .setItems(fileNames, (dialog, which) -> new BackupUtils(this).restoreZipBackupV2Legacy(files[which]))
.show();
}
diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/backup/BackupUtils.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/backup/BackupUtils.java
index 96ffdf5c..e81f73a9 100644
--- a/app/src/main/java/org/torproject/android/ui/hiddenservices/backup/BackupUtils.java
+++ b/app/src/main/java/org/torproject/android/ui/hiddenservices/backup/BackupUtils.java
@@ -270,6 +270,18 @@ public class BackupUtils {
Toast.makeText(mContext, R.string.error, Toast.LENGTH_LONG).show();
}
+ public void restoreZipBackupV3Legacy(File zipFile) {
+ String backupName = zipFile.getName();
+ ZipIt zip = new ZipIt(null, null, mResolver);
+ String v3Dir = backupName.substring(0, backupName.lastIndexOf('.'));
+ File v3Path = new File(getV3BasePath().getAbsolutePath(), v3Dir);
+ if (zip.unzipLegacy(v3Path.getAbsolutePath(), zipFile))
+ extractConfigFromUnzippedBackupV3(backupName);
+ else
+ Toast.makeText(mContext, R.string.error, Toast.LENGTH_LONG).show();
+ }
+
+
public void restoreZipBackupV2(Uri zipUri) {
Cursor returnCursor = mResolver.query(zipUri, null, null, null, null);
int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
diff --git a/app/src/main/java/org/torproject/android/ui/v3onionservice/OnionServicesActivity.java b/app/src/main/java/org/torproject/android/ui/v3onionservice/OnionServicesActivity.java
index eed43a71..a51ef37c 100644
--- a/app/src/main/java/org/torproject/android/ui/v3onionservice/OnionServicesActivity.java
+++ b/app/src/main/java/org/torproject/android/ui/v3onionservice/OnionServicesActivity.java
@@ -11,7 +11,9 @@ import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;
import android.widget.RadioButton;
+import android.widget.Toast;
+import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
@@ -22,6 +24,8 @@ import org.torproject.android.core.DiskUtils;
import org.torproject.android.core.LocaleHelper;
import org.torproject.android.ui.hiddenservices.backup.BackupUtils;
+import java.io.File;
+
public class OnionServicesActivity extends AppCompatActivity {
static final String BUNDLE_KEY_ID = "id", BUNDLE_KEY_PORT = "port", BUNDLE_KEY_DOMAIN = "domain";
@@ -78,13 +82,31 @@ public class OnionServicesActivity extends AppCompatActivity {
if (DiskUtils.supportsStorageAccessFramework()) {
Intent readFileIntent = DiskUtils.createReadFileIntent("application/zip");
startActivityForResult(readFileIntent, REQUEST_CODE_READ_ZIP_BACKUP);
- } else { // 16, 17, 18
-
+ } else { // APIs 16, 17, 18
+ doRestoreLegacy();
}
}
return super.onOptionsItemSelected(item);
}
+ private void doRestoreLegacy() { // APIs 16, 17, 18
+ File backupDir = DiskUtils.getOrCreateLegacyBackupDir(getString(R.string.app_name));
+ File[] files = backupDir.listFiles((dir, name) -> name.toLowerCase().endsWith(".zip"));
+ if (files == null) return;
+ if (files.length == 0) {
+ Toast.makeText(this, R.string.create_a_backup_first, Toast.LENGTH_LONG).show();
+ return;
+ }
+
+ CharSequence[] fileNames = new CharSequence[files.length];
+ for (int i = 0; i < files.length; i++) fileNames[i] = files[i].getName();
+
+ new AlertDialog.Builder(this)
+ .setTitle(R.string.restore_backup)
+ .setItems(fileNames, (dialog, which) -> new BackupUtils(this).restoreZipBackupV3Legacy(files[which]))
+ .show();
+ }
+
@Override
protected void onActivityResult(int requestCode, int result, Intent data) {
super.onActivityResult(requestCode, result, data);
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits