[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [orbot/master] feedback



commit 11e663be67685f845364d7af1514173441f32b3b
Author: arrase <arrase@xxxxxxxxx>
Date:   Sun Nov 20 22:51:36 2016 +0100

    feedback
---
 .../android/ui/hs/HiddenServicesActivity.java           | 17 +++++++++++++++++
 .../android/ui/hs/dialogs/HSActionsDialog.java          | 10 ++++++++--
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/app/src/main/java/org/torproject/android/ui/hs/HiddenServicesActivity.java b/app/src/main/java/org/torproject/android/ui/hs/HiddenServicesActivity.java
index 26889d0..80b7e81 100644
--- a/app/src/main/java/org/torproject/android/ui/hs/HiddenServicesActivity.java
+++ b/app/src/main/java/org/torproject/android/ui/hs/HiddenServicesActivity.java
@@ -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);
+    }
 }
diff --git a/app/src/main/java/org/torproject/android/ui/hs/dialogs/HSActionsDialog.java b/app/src/main/java/org/torproject/android/ui/hs/dialogs/HSActionsDialog.java
index f490586..8d6ad37 100644
--- a/app/src/main/java/org/torproject/android/ui/hs/dialogs/HSActionsDialog.java
+++ b/app/src/main/java/org/torproject/android/ui/hs/dialogs/HSActionsDialog.java
@@ -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")));
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits