feature added: temporarily disable a hidden service

This commit is contained in:
arrase 2016-12-06 00:27:25 +01:00
parent 94c68579e0
commit 4f7271b76e
6 changed files with 64 additions and 13 deletions

View File

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

View File

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

View File

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

View File

@ -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() {
}

View File

@ -6,43 +6,50 @@
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" />
</LinearLayout>
android:textSize="18sp" />
</LinearLayout>
<Switch
android:id="@+id/hs_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

View File

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