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

[tor-commits] [orbot/master] feature added: temporarily disable a hidden service



commit 4f7271b76e4e23ebe5476a223e1494d7ec7600a8
Author: arrase <arrase@xxxxxxxxx>
Date:   Tue Dec 6 00:27:25 2016 +0100

    feature added: temporarily disable a hidden service
---
 .../hiddenservices/adapters/OnionListAdapter.java  | 29 ++++++++++++++++++++++
 .../ui/hiddenservices/backup/BackupUtils.java      | 10 ++++++++
 .../ui/hiddenservices/database/HSDatabase.java     |  1 +
 .../providers/HSContentProvider.java               |  4 ++-
 app/src/main/res/layout/layout_hs_list_item.xml    | 27 ++++++++++++--------
 .../org/torproject/android/service/TorService.java |  6 +++--
 6 files changed, 64 insertions(+), 13 deletions(-)

diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/adapters/OnionListAdapter.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/adapters/OnionListAdapter.java
index 1edbef2..b9f750a 100644
--- a/app/src/main/java/org/torproject/android/ui/hiddenservices/adapters/OnionListAdapter.java
+++ b/app/src/main/java/org/torproject/android/ui/hiddenservices/adapters/OnionListAdapter.java
@@ -1,12 +1,17 @@
 package org.torproject.android.ui.hiddenservices.adapters;
 
+import android.content.ContentResolver;
+import android.content.ContentValues;
 import android.content.Context;
 import android.database.Cursor;
 import android.support.v4.widget.CursorAdapter;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.CompoundButton;
+import android.widget.Switch;
 import android.widget.TextView;
+import android.widget.Toast;
 
 import org.torproject.android.R;
 import org.torproject.android.ui.hiddenservices.providers.HSContentProvider;
@@ -23,12 +28,36 @@ public class OnionListAdapter extends CursorAdapter {
 
     @Override
     public void bindView(View view, Context context, Cursor cursor) {
+        final Context mContext = context;
+        int id = cursor.getInt(cursor.getColumnIndex(HSContentProvider.HiddenService._ID));
+        final String where = HSContentProvider.HiddenService._ID + "=" + id;
+
         TextView port = (TextView) view.findViewById(R.id.hs_port);
         port.setText(cursor.getString(cursor.getColumnIndex(HSContentProvider.HiddenService.PORT)));
         TextView name = (TextView) view.findViewById(R.id.hs_name);
         name.setText(cursor.getString(cursor.getColumnIndex(HSContentProvider.HiddenService.NAME)));
         TextView domain = (TextView) view.findViewById(R.id.hs_onion);
         domain.setText(cursor.getString(cursor.getColumnIndex(HSContentProvider.HiddenService.DOMAIN)));
+        Switch enabled = (Switch) view.findViewById(R.id.hs_switch);
+        enabled.setChecked(
+                cursor.getInt(cursor.getColumnIndex(HSContentProvider.HiddenService.ENABLED)) == 1
+        );
+
+        enabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+            @Override
+            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+                ContentResolver resolver = mContext.getContentResolver();
+                ContentValues fields = new ContentValues();
+                fields.put(HSContentProvider.HiddenService.ENABLED, isChecked);
+                resolver.update(
+                        HSContentProvider.CONTENT_URI, fields, where, null
+                );
+
+                Toast.makeText(
+                        mContext, R.string.please_restart_Orbot_to_enable_the_changes, Toast.LENGTH_LONG
+                ).show();
+            }
+        });
     }
 
     @Override
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 1dccbf8..58911d9 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
@@ -102,6 +102,11 @@ public class BackupUtils {
                     HSContentProvider.HiddenService.CREATED_BY_USER,
                     portData.getInt(portData.getColumnIndex(HSContentProvider.HiddenService.CREATED_BY_USER))
             );
+
+            config.put(
+                    HSContentProvider.HiddenService.ENABLED,
+                    portData.getInt(portData.getColumnIndex(HSContentProvider.HiddenService.ENABLED))
+            );
         } catch (JSONException e) {
             e.printStackTrace();
             return null;
@@ -193,6 +198,11 @@ public class BackupUtils {
                     savedValues.getInt(HSContentProvider.HiddenService.CREATED_BY_USER)
             );
 
+            fields.put(
+                    HSContentProvider.HiddenService.ENABLED,
+                    savedValues.getInt(HSContentProvider.HiddenService.ENABLED)
+            );
+
             port = savedValues.getInt(HSContentProvider.HiddenService.PORT);
             fields.put(HSContentProvider.HiddenService.PORT, port);
 
diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/database/HSDatabase.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/database/HSDatabase.java
index 93ccd25..779c775 100644
--- a/app/src/main/java/org/torproject/android/ui/hiddenservices/database/HSDatabase.java
+++ b/app/src/main/java/org/torproject/android/ui/hiddenservices/database/HSDatabase.java
@@ -19,6 +19,7 @@ public class HSDatabase extends SQLiteOpenHelper {
                     "auth_cookie INTEGER DEFAULT 0, " +
                     "auth_cookie_value TEXT, " +
                     "created_by_user INTEGER DEFAULT 0, " +
+                    "enabled INTEGER DEFAULT 1, " +
                     "port INTEGER);";
 
     public HSDatabase(Context context) {
diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/providers/HSContentProvider.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/providers/HSContentProvider.java
index a0e85dd..d7b558f 100644
--- a/app/src/main/java/org/torproject/android/ui/hiddenservices/providers/HSContentProvider.java
+++ b/app/src/main/java/org/torproject/android/ui/hiddenservices/providers/HSContentProvider.java
@@ -24,7 +24,8 @@ public class HSContentProvider extends ContentProvider {
             HiddenService.ONION_PORT,
             HiddenService.AUTH_COOKIE,
             HiddenService.AUTH_COOKIE_VALUE,
-            HiddenService.CREATED_BY_USER
+            HiddenService.CREATED_BY_USER,
+            HiddenService.ENABLED
     };
     private static final String AUTH = "org.torproject.android.ui.hiddenservices.providers";
     public static final Uri CONTENT_URI =
@@ -135,6 +136,7 @@ public class HSContentProvider extends ContentProvider {
         public static final String AUTH_COOKIE = "auth_cookie";
         public static final String AUTH_COOKIE_VALUE = "auth_cookie_value";
         public static final String CREATED_BY_USER = "created_by_user";
+        public static final String ENABLED = "enabled";
 
         private HiddenService() {
         }
diff --git a/app/src/main/res/layout/layout_hs_list_item.xml b/app/src/main/res/layout/layout_hs_list_item.xml
index d55f688..c8878b0 100644
--- a/app/src/main/res/layout/layout_hs_list_item.xml
+++ b/app/src/main/res/layout/layout_hs_list_item.xml
@@ -6,44 +6,51 @@
     android:orientation="vertical">
 
     <LinearLayout
-        android:orientation="horizontal"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:orientation="horizontal"
         android:paddingLeft="15dp"
-        tools:paddingLeft="15dp">
+        android:paddingRight="15dp"
+        tools:paddingLeft="15dp"
+        tools:paddingRight="15dp">
 
         <TextView
-            android:layout_height="match_parent"
             android:id="@+id/hs_port"
             android:layout_width="wrap_content"
-            android:paddingTop="10dp"
+            android:layout_height="match_parent"
             android:paddingRight="10dp"
+            android:paddingTop="10dp"
             android:textSize="35sp" />
 
         <LinearLayout
-            android:orientation="vertical"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_weight="1">
+            android:layout_weight="1"
+            android:orientation="vertical">
 
             <TextView
                 android:id="@+id/hs_name"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
-                android:textSize="24sp"
+                android:paddingBottom="10dp"
                 android:paddingLeft="10dp"
-                android:paddingBottom="10dp" />
+                android:textSize="24sp" />
 
             <TextView
                 android:id="@+id/hs_onion"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
-                android:textSize="18sp"
+                android:paddingBottom="10dp"
                 android:paddingLeft="10dp"
-                android:paddingBottom="10dp" />
+                android:textSize="18sp" />
 
         </LinearLayout>
 
+        <Switch
+            android:id="@+id/hs_switch"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content" />
+
     </LinearLayout>
 
 </LinearLayout>
\ 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 ff37d8c..19fb0d1 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/TorService.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/TorService.java
@@ -142,6 +142,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
         public static final String AUTH_COOKIE = "auth_cookie";
         public static final String AUTH_COOKIE_VALUE = "auth_cookie_value";
         public static final String CREATED_BY_USER = "created_by_user";
+        public static final String ENABLED = "enabled";
 
         private HiddenService() {
         }
@@ -154,7 +155,8 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
 			HiddenService.PORT,
 			HiddenService.AUTH_COOKIE,
 			HiddenService.AUTH_COOKIE_VALUE,
-			HiddenService.ONION_PORT};
+			HiddenService.ONION_PORT,
+            HiddenService.ENABLED};
 
     public void debug(String msg)
     {
@@ -1792,7 +1794,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
 
         /* ---- Hidden Services ---- */
         ContentResolver mCR = getApplicationContext().getContentResolver();
-        Cursor hidden_services = mCR.query(CONTENT_URI, mProjection, null, null, null);
+        Cursor hidden_services = mCR.query(CONTENT_URI, mProjection, HiddenService.ENABLED + "=1", null, null);
         if(hidden_services != null) {
             try {
                 while (hidden_services.moveToNext()) {



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