notification_stop_button_amoghbl1.patch

Also contains the notification updater patch in it! - amoghbl1, 12/15/2013 09:16 pm

Download (19.2 KB)

View differences:

project.properties
8 8
# project structure.
9 9

  
10 10
# Project target.
11
target=android-17
11
target=android-18
12 12
android.library.reference.1=external/ActionBarSherlock/actionbarsherlock
src/org/torproject/android/service/TorService.java
100 100
	private long lastRead = -1;
101 101
	private long lastWritten = -1;
102 102
	
103
	private static int notificationCounter = 0;
103 104
	
104 105
	private NotificationManager mNotificationManager = null;
105 106
	
......
1180 1181
			mTotalTrafficRead += read;
1181 1182
			
1182 1183
			sendCallbackStatusMessage(written, read, mTotalTrafficWritten, mTotalTrafficRead); 
1184

  
1185
			if (++notificationCounter%10==0)
1186
			    startService(new Intent(INTENT_TOR_SERVICE));
1183 1187
		}
1184 1188
		
1185 1189
		lastWritten = written;
1186
- 
src/org/torproject/android/service/TorService.java
100 100
	private long lastRead = -1;
101 101
	private long lastWritten = -1;
102 102
	
103
	private static int notificationCounter = 0;
104 103
	
105 104
	private NotificationManager mNotificationManager = null;
106 105
	
......
1181 1180
			mTotalTrafficRead += read;
1182 1181
			
1183 1182
			sendCallbackStatusMessage(written, read, mTotalTrafficWritten, mTotalTrafficRead); 
1184

  
1185
			if (++notificationCounter%10==0)
1186
			    startService(new Intent(INTENT_TOR_SERVICE));
1187 1183
		}
1188 1184
		
1189 1185
		lastWritten = written;
1190
- 
patches/amoghbl1_notification_updater.patch
1
From bf4b17acd6beb6d7e5e85c46a4d290a3e3080f5c Mon Sep 17 00:00:00 2001
2
From: amoghbl1 <amoghbl1@gmail.com>
3
Date: Fri, 13 Dec 2013 03:41:05 +0530
4
Subject: [PATCH] notification bug fix
5

  
6
---
7
 src/org/torproject/android/service/TorService.java | 10 ++++++++--
8
 1 file changed, 8 insertions(+), 2 deletions(-)
9

  
10
diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java
11
index 69b46fd..90bebb6 100644
12
--- a/src/org/torproject/android/service/TorService.java
13
+++ b/src/org/torproject/android/service/TorService.java
14
@@ -99,8 +99,10 @@ public class TorService extends Service implements TorServiceConstants, TorConst
15
 
16
 	private long lastRead = -1;
17
 	private long lastWritten = -1;
18
-	
19
-	
20
+
21
+
22
+	private static int notificationCounter = 0;
23
+
24
 	private NotificationManager mNotificationManager = null;
25
 	
26
     public void logMessage(String msg)
27
@@ -1180,6 +1182,10 @@ public class TorService extends Service implements TorServiceConstants, TorConst
28
 			mTotalTrafficRead += read;
29
 			
30
 			sendCallbackStatusMessage(written, read, mTotalTrafficWritten, mTotalTrafficRead); 
31
+
32
+			if(++notificationCounter%10==0)
33
+			    startService(new Intent(INTENT_TOR_SERVICE));
34
+
35
 		}
36
 		
37
 		lastWritten = written;
38
-- 
39
1.8.3.2
40

  
0
- 
src/org/torproject/android/service/TorService.java
33 33
import org.torproject.android.share.ShareItem;
34 34
import org.torproject.android.share.ShareService;
35 35

  
36
import android.annotation.SuppressLint;
36 37
import android.app.Application;
37 38
import android.app.Notification;
38 39
import android.app.NotificationManager;
......
201 202
	}
202 203
   
203 204
	
205
	@SuppressLint("NewApi")
204 206
	private void showToolbarNotification (String notifyMsg, int notifyId, int icon, int flags)
205 207
	{
206 208
	
......
209 211
		CharSequence tickerText = notifyMsg;
210 212
		long when = System.currentTimeMillis();
211 213

  
214
		/*
212 215
		Notification notification = new Notification(icon, tickerText, when);
213 216
		
214 217
		if (prefPersistNotifications && flags != -1)			
......
222 225
		PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
223 226

  
224 227
		notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
228
		*/
229
		Intent notificationIntent = new Intent(this, Orbot.class);
230
		PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
231
		
232
		Notification notification = new Notification.Builder(this)
233
					.setContentTitle(getString(R.string.app_name))
234
					.setContentText(notifyMsg)
235
					.setContentIntent(contentIntent)
236
					.build();
237
		if (prefPersistNotifications && flags != -1)			
238
			notification.flags |= flags;
225 239

  
226 240
		mNotificationManager.notify(notifyId, notification);
227 241

  
228
- 
src/org/torproject/android/service/TorService.java
33 33
import org.torproject.android.share.ShareItem;
34 34
import org.torproject.android.share.ShareService;
35 35

  
36
import android.annotation.SuppressLint;
37 36
import android.app.Application;
38 37
import android.app.Notification;
39 38
import android.app.NotificationManager;
......
202 201
	}
203 202
   
204 203
	
205
	@SuppressLint("NewApi")
206 204
	private void showToolbarNotification (String notifyMsg, int notifyId, int icon, int flags)
207 205
	{
208 206
	
......
211 209
		CharSequence tickerText = notifyMsg;
212 210
		long when = System.currentTimeMillis();
213 211

  
214
		/*
215 212
		Notification notification = new Notification(icon, tickerText, when);
216 213
		
217 214
		if (prefPersistNotifications && flags != -1)			
......
225 222
		PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
226 223

  
227 224
		notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
228
		*/
229
		Intent notificationIntent = new Intent(this, Orbot.class);
230
		PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
231
		
232
		Notification notification = new Notification.Builder(this)
233
					.setContentTitle(getString(R.string.app_name))
234
					.setContentText(notifyMsg)
235
					.setContentIntent(contentIntent)
236
					.build();
237
		if (prefPersistNotifications && flags != -1)			
238
			notification.flags |= flags;
239 225

  
240 226
		mNotificationManager.notify(notifyId, notification);
241 227

  
242
- 
.settings/org.eclipse.jdt.core.prefs
1
eclipse.preferences.version=1
2
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3
org.eclipse.jdt.core.compiler.compliance=1.6
4
org.eclipse.jdt.core.compiler.source=1.6
src/org/torproject/android/Orbot.java
97 97
        	StrictMode.setVmPolicy(vmpolicy);
98 98
        	}
99 99
        */
100

  
100
        //Kill tor if the button stop tor (in the notification) was clicked!
101
        //Same code needs to be executed in onResume
102
        
101 103
        mPrefs = getPrefs();
102 104
        mPrefs.registerOnSharedPreferenceChangeListener(this);
103 105
        
......
438 440
		
439 441
		super.onNewIntent(intent);
440 442
		
443
		int stopTorFlag=intent.getIntExtra("stopTorFlag", 0);
444
        if(stopTorFlag==1)
445
        {
446
        	try {
447
				stopTor();
448
			} catch (RemoteException e) {
449
				// TODO Auto-generated catch block
450
				e.printStackTrace();
451
			}
452
        	android.os.Process.killProcess(android.os.Process.myPid());
453
        }
441 454
		updateStatus("");
442 455
		handleIntents();
443 456
	}
src/org/torproject/android/service/TorService.java
33 33
import org.torproject.android.share.ShareItem;
34 34
import org.torproject.android.share.ShareService;
35 35

  
36
import android.annotation.SuppressLint;
36 37
import android.app.Application;
37 38
import android.app.Notification;
38 39
import android.app.NotificationManager;
......
99 100

  
100 101
	private long lastRead = -1;
101 102
	private long lastWritten = -1;
102
	
103
	
103

  
104

  
105
	private static int notificationCounter = 0;
106

  
104 107
	private NotificationManager mNotificationManager = null;
105 108
	
106 109
    public void logMessage(String msg)
......
201 204
	}
202 205
   
203 206
	
207
	@SuppressLint("NewApi")
204 208
	private void showToolbarNotification (String notifyMsg, int notifyId, int icon, int flags)
205 209
	{
206 210
	
207 211
		
208
		
212
		/*
209 213
		CharSequence tickerText = notifyMsg;
210 214
		long when = System.currentTimeMillis();
211 215

  
216
		
212 217
		Notification notification = new Notification(icon, tickerText, when);
213 218
		
214 219
		if (prefPersistNotifications && flags != -1)			
......
222 227
		PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
223 228

  
224 229
		notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
230
		 */
231
		Intent notificationIntent = new Intent(this, Orbot.class);
232
		PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
233
				
234
		Notification notification = new Notification.Builder(this)
235
					.setContentTitle(getString(R.string.app_name))
236
					.setContentText(notifyMsg)
237
					.setContentIntent(contentIntent) 
238
					.setSmallIcon(icon)
239
					.build();
240
		if (prefPersistNotifications && flags != -1)			
241
			notification.flags |= flags;
225 242

  
226 243
		mNotificationManager.notify(notifyId, notification);
227 244

  
228

  
229 245
	}
230 246
    
231 247
    /* (non-Javadoc)
......
1055 1071
			}
1056 1072
		}
1057 1073
		
1058
		NotificationCompat.Builder mNotifyBuilder;
1074
		Notification.Builder mNotifyBuilder;
1059 1075
		
1076
		@SuppressLint("NewApi")
1060 1077
		private void startNotification (String message, boolean persistent)
1061 1078
		{
1062 1079
			
1063 1080
			if (mNotifyBuilder == null)
1064 1081
			{
1065
				mNotifyBuilder = new NotificationCompat.Builder(this)
1082

  
1083
				Intent stopTor = new Intent(this,Orbot.class);
1084
				stopTor.putExtra("stopTorFlag", 1);
1085
				PendingIntent stopTorIntent = PendingIntent.getActivity(this, 0, stopTor, 0);
1086
				
1087
				mNotifyBuilder = new Notification.Builder(this)
1066 1088
				    .setContentTitle(getString(R.string.app_name))
1067 1089
				    .setContentText( getString(R.string.status_activated))
1068
				    .setSmallIcon(R.drawable.ic_stat_tor);
1090
				    .setSmallIcon(R.drawable.ic_stat_tor)
1091
				    .addAction(R.drawable.icon, "STOP", stopTorIntent);
1069 1092
			
1070 1093
				Intent intent = new Intent(TorService.this, Orbot.class);
1071 1094
				PendingIntent pendIntent = PendingIntent.getActivity(TorService.this, 0, intent, 0);
......
1180 1203
			mTotalTrafficRead += read;
1181 1204
			
1182 1205
			sendCallbackStatusMessage(written, read, mTotalTrafficWritten, mTotalTrafficRead); 
1206

  
1207
			if(++notificationCounter%10==0)
1208
			    startService(new Intent(INTENT_TOR_SERVICE));
1209

  
1183 1210
		}
1184 1211
		
1185 1212
		lastWritten = written;
src/org/torproject/android/service/TorService.java
1088 1088
				    .setContentTitle(getString(R.string.app_name))
1089 1089
				    .setContentText( getString(R.string.status_activated))
1090 1090
				    .setSmallIcon(R.drawable.ic_stat_tor)
1091
				    .addAction(R.drawable.icon, "STOP", stopTorIntent);
1091
				    .addAction(R.drawable.button_stop, "STOP", stopTorIntent);
1092 1092
			
1093 1093
				Intent intent = new Intent(TorService.this, Orbot.class);
1094 1094
				PendingIntent pendIntent = PendingIntent.getActivity(TorService.this, 0, intent, 0);
1095
-