[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [orbot/master] Add DisableNetwork support
commit dbdadf211557e98e76bf64dd4d9677ac099f4472
Author: Sathyanarayanan Gunasekaran <gsathya.ceg@xxxxxxxxx>
Date: Sun Sep 30 20:41:54 2012 +0530
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.
---
AndroidManifest.xml | 7 +++--
src/org/torproject/android/service/TorService.java | 22 ++++++++++++++++++++
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 99ce90b..9ff495c 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -5,9 +5,10 @@
android:versionCode="45"
android:installLocation="auto"
>
- <uses-permission android:name="android.permission.INTERNET" />
- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
-
+ <uses-permission android:name="android.permission.INTERNET" />
+ <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"/>
<application android:name=".OrbotApp" android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java
index 73c0d71..7711648 100644
--- a/src/org/torproject/android/service/TorService.java
+++ b/src/org/torproject/android/service/TorService.java
@@ -38,10 +38,13 @@ import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
+import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
+import android.net.ConnectivityManager;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Looper;
@@ -275,6 +278,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
{
initTor();
isRunning = true;
+ IntentFilter mNetworkStateFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
+ registerReceiver(mNetworkStateReceiver , mNetworkStateFilter);
}
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
{
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits