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 1edbef22..b9f750ac 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 1dccbf85..58911d9f 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 93ccd25a..779c7756 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 a0e85dd4..d7b558fd 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 d55f6880..c8878b0e 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"> + android:paddingRight="15dp" + tools:paddingLeft="15dp" + tools:paddingRight="15dp"> + android:layout_weight="1" + android:orientation="vertical"> + android:textSize="24sp" /> + android:textSize="18sp" /> + + \ 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 ff37d8cf..19fb0d12 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()) {