From fca54cfcdc2407810621dd5247de262cfc0d495a Mon Sep 17 00:00:00 2001 From: arrase Date: Sun, 27 Nov 2016 16:03:38 +0100 Subject: [PATCH] move hidden services to files directory --- app/build.gradle | 7 ---- app/src/main/AndroidManifest.xml | 4 +- .../ui/hiddenservices/backup/BackupUtils.java | 16 +++----- .../storage/AppDataProvider.java | 39 ------------------- .../main/res/xml/hidden_services_paths.xml | 3 +- .../android/service/TorService.java | 8 ++-- 6 files changed, 14 insertions(+), 63 deletions(-) delete mode 100644 app/src/main/java/org/torproject/android/ui/hiddenservices/storage/AppDataProvider.java diff --git a/app/build.gradle b/app/build.gradle index 7debed3e..cc364c78 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,16 +26,9 @@ android { } } -repositories { - maven { - url "https://s3.amazonaws.com/repo.commonsware.com" - } -} - dependencies { compile project(':orbotservice') compile 'com.android.support:support-v4:23.4.0' compile 'com.android.support:appcompat-v7:23.4.0' compile 'com.android.support:design:23.4.0' - compile 'com.commonsware.cwac:provider:0.4.4' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b7a5e879..1704c703 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -151,12 +151,12 @@ android:authorities="org.torproject.android.ui.hiddenservices.providers" /> 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 c60beb91..70da3022 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 @@ -1,6 +1,5 @@ package org.torproject.android.ui.hiddenservices.backup; -import android.app.Application; import android.content.Context; import android.widget.Toast; @@ -17,9 +16,9 @@ public class BackupUtils { public BackupUtils(Context context) { mContext = context; - mHSBasePath = mContext.getDir( - TorServiceConstants.DIRECTORY_TOR_DATA, - Application.MODE_PRIVATE + mHSBasePath = new File( + mContext.getFilesDir().getAbsolutePath(), + TorServiceConstants.HIDDEN_SERVICES_DIR ); } @@ -32,8 +31,8 @@ public class BackupUtils { String zip_path = storage_path.getAbsolutePath() + "/hs" + port + ".zip"; String files[] = { - mHSBasePath + "/" + TorServiceConstants.HIDDEN_SERVICES_DIR + "/hs" + port + "/hostname", - mHSBasePath + "/" + TorServiceConstants.HIDDEN_SERVICES_DIR + "/hs" + port + "/private_key" + mHSBasePath + "/hs" + port + "/hostname", + mHSBasePath + "/hs" + port + "/private_key" }; ZipIt zip = new ZipIt(files, zip_path); @@ -46,11 +45,8 @@ public class BackupUtils { } public void restoreZipBackup(Integer port, String path) { - String hsBasePath; - try { - hsBasePath = mHSBasePath.getCanonicalPath() + "/" + TorServiceConstants.HIDDEN_SERVICES_DIR; - File hsPath = new File(hsBasePath, "/hs" + port); + File hsPath = new File(mHSBasePath.getCanonicalPath(), "/hs" + port); if (hsPath.mkdirs()) { ZipIt zip = new ZipIt(null, path); zip.unzip(hsPath.getCanonicalPath()); diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/storage/AppDataProvider.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/storage/AppDataProvider.java deleted file mode 100644 index 6e555694..00000000 --- a/app/src/main/java/org/torproject/android/ui/hiddenservices/storage/AppDataProvider.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.torproject.android.ui.hiddenservices.storage; - - -import android.app.Application; -import android.content.Context; - -import com.commonsware.cwac.provider.LocalPathStrategy; -import com.commonsware.cwac.provider.StreamProvider; -import com.commonsware.cwac.provider.StreamStrategy; - -import org.torproject.android.service.TorServiceConstants; - -import java.io.IOException; -import java.util.HashMap; - -public class AppDataProvider extends StreamProvider { - private static final String TAG = "app-data-path"; - - @Override - protected StreamStrategy buildStrategy(Context context, - String tag, String name, - String path, - HashMap attrs) - throws IOException { - - if (TAG.equals(tag)) { - return (new LocalPathStrategy( - name, - context.getDir( - TorServiceConstants.DIRECTORY_TOR_DATA, - Application.MODE_PRIVATE - ) - ) - ); - } - - return (super.buildStrategy(context, tag, name, path, attrs)); - } -} diff --git a/app/src/main/res/xml/hidden_services_paths.xml b/app/src/main/res/xml/hidden_services_paths.xml index 943fd09f..073732b6 100644 --- a/app/src/main/res/xml/hidden_services_paths.xml +++ b/app/src/main/res/xml/hidden_services_paths.xml @@ -1,5 +1,4 @@ - - + \ No newline at end of file diff --git a/orbotservice/src/main/java/org/torproject/android/service/TorService.java b/orbotservice/src/main/java/org/torproject/android/service/TorService.java index 6d124246..c2a2431c 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/TorService.java +++ b/orbotservice/src/main/java/org/torproject/android/service/TorService.java @@ -531,11 +531,13 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon fileXtables = new File(appBinHome, TorServiceConstants.IPTABLES_ASSET_KEY); fileTorRc = new File(appBinHome, TorServiceConstants.TORRC_ASSET_KEY); - mHSBasePath = new File(appCacheHome , TorServiceConstants.HIDDEN_SERVICES_DIR); + mHSBasePath = new File( + getFilesDir().getAbsolutePath(), + TorServiceConstants.HIDDEN_SERVICES_DIR + ); - if (!mHSBasePath.isDirectory()) { + if (!mHSBasePath.isDirectory()) mHSBasePath.mkdirs(); - } mEventHandler = new TorEventHandler(this);