Add DisableNetwork support
DisableNetwork tells tor to drop the current circuits and stop building new ones. A BroadcastReciever is triggered when there are changes in the network connection which toggles DisableNetwork.
This commit is contained in:
parent
efc6d95314
commit
dbdadf2115
|
@ -5,9 +5,10 @@
|
||||||
android:versionCode="45"
|
android:versionCode="45"
|
||||||
android:installLocation="auto"
|
android:installLocation="auto"
|
||||||
>
|
>
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
|
||||||
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="15"/>
|
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="15"/>
|
||||||
<application android:name=".OrbotApp" android:icon="@drawable/ic_launcher"
|
<application android:name=".OrbotApp" android:icon="@drawable/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
|
|
|
@ -38,10 +38,13 @@ import android.app.Notification;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.SharedPreferences.Editor;
|
import android.content.SharedPreferences.Editor;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
@ -275,6 +278,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
{
|
{
|
||||||
initTor();
|
initTor();
|
||||||
isRunning = true;
|
isRunning = true;
|
||||||
|
IntentFilter mNetworkStateFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||||
|
registerReceiver(mNetworkStateReceiver , mNetworkStateFilter);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -1496,6 +1501,23 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Another way to do this would be to use the Observer pattern by defining the
|
||||||
|
* BroadcastReciever in the Android manifest.
|
||||||
|
*/
|
||||||
|
private final BroadcastReceiver mNetworkStateReceiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
boolean noConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
|
||||||
|
try {
|
||||||
|
mBinder.updateConfiguration("DisableNetwork", noConnectivity ? "1" : "0", false);
|
||||||
|
mBinder.saveConfiguration();
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
logException ("error applying prefs",e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private boolean updateTorConfiguration () throws RemoteException
|
private boolean updateTorConfiguration () throws RemoteException
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue