feature added: temporarily disable a hidden service
This commit is contained in:
parent
94c68579e0
commit
4f7271b76e
|
@ -1,12 +1,17 @@
|
||||||
package org.torproject.android.ui.hiddenservices.adapters;
|
package org.torproject.android.ui.hiddenservices.adapters;
|
||||||
|
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.support.v4.widget.CursorAdapter;
|
import android.support.v4.widget.CursorAdapter;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.Switch;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.torproject.android.R;
|
import org.torproject.android.R;
|
||||||
import org.torproject.android.ui.hiddenservices.providers.HSContentProvider;
|
import org.torproject.android.ui.hiddenservices.providers.HSContentProvider;
|
||||||
|
@ -23,12 +28,36 @@ public class OnionListAdapter extends CursorAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindView(View view, Context context, Cursor cursor) {
|
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);
|
TextView port = (TextView) view.findViewById(R.id.hs_port);
|
||||||
port.setText(cursor.getString(cursor.getColumnIndex(HSContentProvider.HiddenService.PORT)));
|
port.setText(cursor.getString(cursor.getColumnIndex(HSContentProvider.HiddenService.PORT)));
|
||||||
TextView name = (TextView) view.findViewById(R.id.hs_name);
|
TextView name = (TextView) view.findViewById(R.id.hs_name);
|
||||||
name.setText(cursor.getString(cursor.getColumnIndex(HSContentProvider.HiddenService.NAME)));
|
name.setText(cursor.getString(cursor.getColumnIndex(HSContentProvider.HiddenService.NAME)));
|
||||||
TextView domain = (TextView) view.findViewById(R.id.hs_onion);
|
TextView domain = (TextView) view.findViewById(R.id.hs_onion);
|
||||||
domain.setText(cursor.getString(cursor.getColumnIndex(HSContentProvider.HiddenService.DOMAIN)));
|
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
|
@Override
|
||||||
|
|
|
@ -102,6 +102,11 @@ public class BackupUtils {
|
||||||
HSContentProvider.HiddenService.CREATED_BY_USER,
|
HSContentProvider.HiddenService.CREATED_BY_USER,
|
||||||
portData.getInt(portData.getColumnIndex(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) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
|
@ -193,6 +198,11 @@ public class BackupUtils {
|
||||||
savedValues.getInt(HSContentProvider.HiddenService.CREATED_BY_USER)
|
savedValues.getInt(HSContentProvider.HiddenService.CREATED_BY_USER)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
fields.put(
|
||||||
|
HSContentProvider.HiddenService.ENABLED,
|
||||||
|
savedValues.getInt(HSContentProvider.HiddenService.ENABLED)
|
||||||
|
);
|
||||||
|
|
||||||
port = savedValues.getInt(HSContentProvider.HiddenService.PORT);
|
port = savedValues.getInt(HSContentProvider.HiddenService.PORT);
|
||||||
fields.put(HSContentProvider.HiddenService.PORT, port);
|
fields.put(HSContentProvider.HiddenService.PORT, port);
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ public class HSDatabase extends SQLiteOpenHelper {
|
||||||
"auth_cookie INTEGER DEFAULT 0, " +
|
"auth_cookie INTEGER DEFAULT 0, " +
|
||||||
"auth_cookie_value TEXT, " +
|
"auth_cookie_value TEXT, " +
|
||||||
"created_by_user INTEGER DEFAULT 0, " +
|
"created_by_user INTEGER DEFAULT 0, " +
|
||||||
|
"enabled INTEGER DEFAULT 1, " +
|
||||||
"port INTEGER);";
|
"port INTEGER);";
|
||||||
|
|
||||||
public HSDatabase(Context context) {
|
public HSDatabase(Context context) {
|
||||||
|
|
|
@ -24,7 +24,8 @@ public class HSContentProvider extends ContentProvider {
|
||||||
HiddenService.ONION_PORT,
|
HiddenService.ONION_PORT,
|
||||||
HiddenService.AUTH_COOKIE,
|
HiddenService.AUTH_COOKIE,
|
||||||
HiddenService.AUTH_COOKIE_VALUE,
|
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";
|
private static final String AUTH = "org.torproject.android.ui.hiddenservices.providers";
|
||||||
public static final Uri CONTENT_URI =
|
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 = "auth_cookie";
|
||||||
public static final String AUTH_COOKIE_VALUE = "auth_cookie_value";
|
public static final String AUTH_COOKIE_VALUE = "auth_cookie_value";
|
||||||
public static final String CREATED_BY_USER = "created_by_user";
|
public static final String CREATED_BY_USER = "created_by_user";
|
||||||
|
public static final String ENABLED = "enabled";
|
||||||
|
|
||||||
private HiddenService() {
|
private HiddenService() {
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,43 +6,50 @@
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="horizontal"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
android:paddingLeft="15dp"
|
android:paddingLeft="15dp"
|
||||||
tools:paddingLeft="15dp">
|
android:paddingRight="15dp"
|
||||||
|
tools:paddingLeft="15dp"
|
||||||
|
tools:paddingRight="15dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:id="@+id/hs_port"
|
android:id="@+id/hs_port"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:paddingTop="10dp"
|
android:layout_height="match_parent"
|
||||||
android:paddingRight="10dp"
|
android:paddingRight="10dp"
|
||||||
|
android:paddingTop="10dp"
|
||||||
android:textSize="35sp" />
|
android:textSize="35sp" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1">
|
android:layout_weight="1"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/hs_name"
|
android:id="@+id/hs_name"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textSize="24sp"
|
android:paddingBottom="10dp"
|
||||||
android:paddingLeft="10dp"
|
android:paddingLeft="10dp"
|
||||||
android:paddingBottom="10dp" />
|
android:textSize="24sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/hs_onion"
|
android:id="@+id/hs_onion"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textSize="18sp"
|
android:paddingBottom="10dp"
|
||||||
android:paddingLeft="10dp"
|
android:paddingLeft="10dp"
|
||||||
android:paddingBottom="10dp" />
|
android:textSize="18sp" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<Switch
|
||||||
|
android:id="@+id/hs_switch"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
|
@ -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 = "auth_cookie";
|
||||||
public static final String AUTH_COOKIE_VALUE = "auth_cookie_value";
|
public static final String AUTH_COOKIE_VALUE = "auth_cookie_value";
|
||||||
public static final String CREATED_BY_USER = "created_by_user";
|
public static final String CREATED_BY_USER = "created_by_user";
|
||||||
|
public static final String ENABLED = "enabled";
|
||||||
|
|
||||||
private HiddenService() {
|
private HiddenService() {
|
||||||
}
|
}
|
||||||
|
@ -154,7 +155,8 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
||||||
HiddenService.PORT,
|
HiddenService.PORT,
|
||||||
HiddenService.AUTH_COOKIE,
|
HiddenService.AUTH_COOKIE,
|
||||||
HiddenService.AUTH_COOKIE_VALUE,
|
HiddenService.AUTH_COOKIE_VALUE,
|
||||||
HiddenService.ONION_PORT};
|
HiddenService.ONION_PORT,
|
||||||
|
HiddenService.ENABLED};
|
||||||
|
|
||||||
public void debug(String msg)
|
public void debug(String msg)
|
||||||
{
|
{
|
||||||
|
@ -1792,7 +1794,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
||||||
|
|
||||||
/* ---- Hidden Services ---- */
|
/* ---- Hidden Services ---- */
|
||||||
ContentResolver mCR = getApplicationContext().getContentResolver();
|
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) {
|
if(hidden_services != null) {
|
||||||
try {
|
try {
|
||||||
while (hidden_services.moveToNext()) {
|
while (hidden_services.moveToNext()) {
|
||||||
|
|
Loading…
Reference in New Issue