move hidden services to files directory

This commit is contained in:
arrase 2016-11-27 16:03:38 +01:00
parent a49ac3fcc5
commit fca54cfcdc
6 changed files with 14 additions and 63 deletions

View File

@ -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'
}

View File

@ -151,12 +151,12 @@
android:authorities="org.torproject.android.ui.hiddenservices.providers" />
<provider
android:name=".ui.hiddenservices.storage.AppDataProvider"
android:name="android.support.v4.content.FileProvider"
android:authorities="org.torproject.android.ui.hiddenservices.storage"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="com.commonsware.cwac.provider.STREAM_PROVIDER_PATHS"
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/hidden_services_paths"/>
</provider>
</application>

View File

@ -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());

View File

@ -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<String, String> 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));
}
}

View File

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<app-data-path name="hidden-services" path="hidden_services/"/>
<files-path name="hidden-services" path="hidden_services/" />
</paths>

View File

@ -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);