This commit is contained in:
arrase 2016-11-20 22:51:36 +01:00
parent 3e6c627712
commit 11e663be67
2 changed files with 25 additions and 2 deletions

View File

@ -1,8 +1,12 @@
package org.torproject.android.ui.hs;
import android.Manifest;
import android.annotation.SuppressLint;
import android.content.ContentResolver;
import android.content.pm.PackageManager;
import android.database.ContentObserver;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
@ -82,6 +86,10 @@ public class HiddenServicesActivity extends AppCompatActivity {
Bundle arguments = new Bundle();
arguments.putString("port", port.getText().toString());
arguments.putString("onion", onion.getText().toString());
boolean has_write_permission = true;
if (usesRuntimePermissions())
has_write_permission = hasPermission();
arguments.putBoolean("has_write_permissions", has_write_permission);
HSActionsDialog dialog = new HSActionsDialog();
dialog.setArguments(arguments);
@ -89,4 +97,13 @@ public class HiddenServicesActivity extends AppCompatActivity {
}
});
}
private boolean usesRuntimePermissions() {
return (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1);
}
@SuppressLint("NewApi")
private boolean hasPermission() {
return (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED);
}
}

View File

@ -32,10 +32,16 @@ public class HSActionsDialog extends DialogFragment {
.setTitle(R.string.hidden_services)
.create();
Button save = (Button) dialog_view.findViewById(R.id.btn_hs_backup);
save.setOnClickListener(new View.OnClickListener() {
Button backup = (Button) dialog_view.findViewById(R.id.btn_hs_backup);
backup.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Context mContext = v.getContext();
if (!arguments.getBoolean("has_write_permissions")) {
Toast.makeText(mContext, R.string.please_grant_permissions_for_external_storage, Toast.LENGTH_LONG).show();
return;
}
HiddenServiceUtils hsutils = new HiddenServiceUtils(mContext);
String backupPath = hsutils.createOnionBackup(Integer.parseInt(arguments.getString("port")));