notification_updater_stop_button_amoghbl1.patch
| 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 |
- |
|
| .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 |
|
| project.properties | ||
|---|---|---|
| 8 | 8 |
# project structure. |
| 9 | 9 | |
| 10 | 10 |
# Project target. |
| 11 |
target=android-18
|
|
| 11 |
target=android-17
|
|
| 12 | 12 |
android.library.reference.1=external/ActionBarSherlock/actionbarsherlock |
| src/org/torproject/android/Orbot.java | ||
|---|---|---|
| 438 | 438 |
|
| 439 | 439 |
super.onNewIntent(intent); |
| 440 | 440 |
|
| 441 |
//Handle the intent which launches this class when the stop button (in notification) is clicked |
|
| 442 |
int stopTorFlag = intent.getIntExtra("stopTorFlag",0);
|
|
| 443 |
//If the stop tor flag was set to 1 then we need to stop the application , by observing the previous code we see that we |
|
| 444 |
//need to call stopTor(). |
|
| 445 |
if(stopTorFlag==1) |
|
| 446 |
{
|
|
| 447 |
try {
|
|
| 448 |
stopTor(); |
|
| 449 |
} catch (RemoteException e) {
|
|
| 450 |
// TODO Auto-generated catch block |
|
| 451 |
e.printStackTrace(); |
|
| 452 |
} |
|
| 453 |
//We also kill the android application process so that the user can return to the application he was on when he clicked the |
|
| 454 |
//stop button. |
|
| 455 |
|
|
| 456 |
android.os.Process.killProcess(android.os.Process.myPid()); |
|
| 457 |
} |
|
| 458 |
|
|
| 441 | 459 |
updateStatus("");
|
| 442 | 460 |
handleIntents(); |
| 443 | 461 |
} |
| 444 |
- |
|
| 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; |
| ... | ... | |
| 202 | 203 |
} |
| 203 | 204 |
|
| 204 | 205 |
|
| 206 |
@SuppressLint("NewApi")
|
|
| 205 | 207 |
private void showToolbarNotification (String notifyMsg, int notifyId, int icon, int flags) |
| 206 | 208 |
{
|
| 207 | 209 |
|
| 208 |
|
|
| 209 |
|
|
| 210 |
CharSequence tickerText = notifyMsg; |
|
| 211 |
long when = System.currentTimeMillis(); |
|
| 212 | ||
| 213 |
Notification notification = new Notification(icon, tickerText, when); |
|
| 214 |
|
|
| 215 |
if (prefPersistNotifications && flags != -1) |
|
| 216 |
notification.flags |= flags; |
|
| 217 | ||
| 218 |
Context context = getApplicationContext(); |
|
| 219 |
CharSequence contentTitle = getString(R.string.app_name); |
|
| 220 |
CharSequence contentText = notifyMsg; |
|
| 221 |
|
|
| 210 |
//Reusable code has been moved here. |
|
| 222 | 211 |
Intent notificationIntent = new Intent(this, Orbot.class); |
| 223 | 212 |
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); |
| 224 | ||
| 225 |
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); |
|
| 226 | ||
| 227 |
mNotificationManager.notify(notifyId, notification); |
|
| 228 | ||
| 229 | ||
| 213 |
|
|
| 214 |
//The code which was originally present here has been modified in order to implement newer standards keeping in mind the |
|
| 215 |
//problem of backward compatibility. |
|
| 216 |
if(Build.VERSION.SDK_INT<Build.VERSION_CODES.JELLY_BEAN) |
|
| 217 |
{
|
|
| 218 |
CharSequence tickerText = notifyMsg; |
|
| 219 |
long when = System.currentTimeMillis(); |
|
| 220 |
|
|
| 221 |
Notification notification = new Notification(icon, tickerText, when); |
|
| 222 |
|
|
| 223 |
if (prefPersistNotifications && flags != -1) |
|
| 224 |
notification.flags |= flags; |
|
| 225 |
|
|
| 226 |
Context context = getApplicationContext(); |
|
| 227 |
CharSequence contentTitle = getString(R.string.app_name); |
|
| 228 |
CharSequence contentText = notifyMsg; |
|
| 229 |
|
|
| 230 |
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); |
|
| 231 |
|
|
| 232 |
mNotificationManager.notify(notifyId, notification); |
|
| 233 |
} |
|
| 234 |
//This is the new code which can be used for versions above api 16 (Jelly Bean). |
|
| 235 |
else if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN) |
|
| 236 |
{
|
|
| 237 |
Notification notification = new Notification.Builder(this) |
|
| 238 |
.setSmallIcon(icon) |
|
| 239 |
.setContentTitle(getString(R.string.app_name)) |
|
| 240 |
.setContentText(notifyMsg) |
|
| 241 |
.setContentIntent(contentIntent) |
|
| 242 |
.build(); |
|
| 243 |
|
|
| 244 |
if (prefPersistNotifications && flags != -1) |
|
| 245 |
notification.flags |= flags; |
|
| 246 |
|
|
| 247 |
mNotificationManager.notify(notifyId,notification); |
|
| 248 |
} |
|
| 230 | 249 |
} |
| 231 | 250 |
|
| 232 | 251 |
/* (non-Javadoc) |
| 233 |
- |
|
| src/org/torproject/android/Orbot.java | ||
|---|---|---|
| 34 | 34 |
import android.os.IBinder; |
| 35 | 35 |
import android.os.Message; |
| 36 | 36 |
import android.os.RemoteException; |
| 37 |
import android.preference.PreferenceManager; |
|
| 38 | 37 |
import android.text.ClipboardManager; |
| 39 | 38 |
import android.text.Layout; |
| 40 | 39 |
import android.text.method.ScrollingMovementMethod; |
| ... | ... | |
| 47 | 46 |
import android.view.View.OnLongClickListener; |
| 48 | 47 |
import android.view.View.OnTouchListener; |
| 49 | 48 |
import android.view.animation.AccelerateInterpolator; |
| 50 |
import android.view.animation.Animation; |
|
| 51 | 49 |
import android.widget.Button; |
| 52 | 50 |
import android.widget.SlidingDrawer; |
| 53 | 51 |
import android.widget.TextView; |
| ... | ... | |
| 442 | 440 |
int stopTorFlag = intent.getIntExtra("stopTorFlag",0);
|
| 443 | 441 |
//If the stop tor flag was set to 1 then we need to stop the application , by observing the previous code we see that we |
| 444 | 442 |
//need to call stopTor(). |
| 443 |
Log.i(TAG,"stopTorFlag"+stopTorFlag); |
|
| 445 | 444 |
if(stopTorFlag==1) |
| 446 | 445 |
{
|
| 447 | 446 |
try {
|
| ... | ... | |
| 452 | 451 |
} |
| 453 | 452 |
//We also kill the android application process so that the user can return to the application he was on when he clicked the |
| 454 | 453 |
//stop button. |
| 455 |
|
|
| 456 |
android.os.Process.killProcess(android.os.Process.myPid()); |
|
| 454 |
//Luckily for me , the unbindService() exitst! If we just try to do this.finish() , we get a service has leaked error |
|
| 455 |
//in the logcat and therefore I have used unbindService() before it and it seems to work perfectly! |
|
| 456 |
unbindService(); |
|
| 457 |
this.finish(); |
|
| 457 | 458 |
} |
| 458 | 459 |
|
| 459 | 460 |
updateStatus("");
|
| src/org/torproject/android/service/TorService.java | ||
|---|---|---|
| 1076 | 1076 |
} |
| 1077 | 1077 |
|
| 1078 | 1078 |
NotificationCompat.Builder mNotifyBuilder; |
| 1079 |
Notification.Builder mNewNotifyBuilder; |
|
| 1079 | 1080 |
|
| 1081 |
@SuppressLint("NewApi")
|
|
| 1080 | 1082 |
private void startNotification (String message, boolean persistent) |
| 1081 | 1083 |
{
|
| 1084 |
//Reusable code. |
|
| 1085 |
Intent intent = new Intent(TorService.this, Orbot.class); |
|
| 1086 |
PendingIntent pendIntent = PendingIntent.getActivity(TorService.this, 0, intent, 0); |
|
| 1082 | 1087 |
|
| 1083 |
if (mNotifyBuilder == null) |
|
| 1088 |
if (mNotificationManager == null) |
|
| 1089 |
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); |
|
| 1090 |
|
|
| 1091 |
//Older version of code is here and will be used if api < 16. |
|
| 1092 |
if(Build.VERSION.SDK_INT<Build.VERSION_CODES.JELLY_BEAN) |
|
| 1084 | 1093 |
{
|
| 1085 |
mNotifyBuilder = new NotificationCompat.Builder(this) |
|
| 1086 |
.setContentTitle(getString(R.string.app_name)) |
|
| 1087 |
.setContentText( getString(R.string.status_activated)) |
|
| 1088 |
.setSmallIcon(R.drawable.ic_stat_tor); |
|
| 1094 |
if (mNotifyBuilder == null) |
|
| 1095 |
{
|
|
| 1096 |
mNotifyBuilder = new NotificationCompat.Builder(this) |
|
| 1097 |
.setContentTitle(getString(R.string.app_name)) |
|
| 1098 |
.setContentText( getString(R.string.status_activated)) |
|
| 1099 |
.setSmallIcon(R.drawable.ic_stat_tor); |
|
| 1100 | ||
| 1101 |
mNotifyBuilder.setContentIntent(pendIntent); |
|
| 1102 |
} |
|
| 1089 | 1103 |
|
| 1090 |
Intent intent = new Intent(TorService.this, Orbot.class);
|
|
| 1091 |
PendingIntent pendIntent = PendingIntent.getActivity(TorService.this, 0, intent, 0);
|
|
| 1104 |
mNotifyBuilder.setOngoing(persistent);
|
|
| 1105 |
mNotifyBuilder.setContentText(message);
|
|
| 1092 | 1106 | |
| 1093 |
mNotifyBuilder.setContentIntent(pendIntent); |
|
| 1107 |
mNotificationManager.notify( |
|
| 1108 |
NOTIFY_ID, |
|
| 1109 |
mNotifyBuilder.getNotification()); |
|
| 1110 |
} |
|
| 1111 |
else if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN) |
|
| 1112 |
{
|
|
| 1113 |
if(mNewNotifyBuilder==null) |
|
| 1114 |
{
|
|
| 1115 |
Intent stopTor = new Intent(this,Orbot.class); |
|
| 1116 |
stopTor.putExtra("stopTorFlag",1);
|
|
| 1117 |
PendingIntent stopTorIntent = PendingIntent.getActivity(this, 0, stopTor, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_UPDATE_CURRENT); |
|
| 1118 |
|
|
| 1119 |
mNewNotifyBuilder = new Notification.Builder(this) |
|
| 1120 |
.setContentTitle(getString(R.string.app_name)) |
|
| 1121 |
.setContentText(getString(R.string.status_activated)) |
|
| 1122 |
.setSmallIcon(R.drawable.ic_stat_tor) |
|
| 1123 |
.addAction(R.drawable.button_stop, "STOP", stopTorIntent); |
|
| 1124 |
|
|
| 1125 |
mNewNotifyBuilder.setContentIntent(pendIntent); |
|
| 1126 |
} |
|
| 1094 | 1127 |
|
| 1128 |
mNewNotifyBuilder.setOngoing(persistent); |
|
| 1129 |
mNewNotifyBuilder.setContentText(message); |
|
| 1095 | 1130 |
|
| 1096 |
} |
|
| 1097 | ||
| 1098 |
if (mNotificationManager == null) |
|
| 1099 |
{
|
|
| 1100 |
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); |
|
| 1101 | ||
| 1131 |
mNotificationManager.notify( |
|
| 1132 |
NOTIFY_ID, |
|
| 1133 |
mNewNotifyBuilder.build()); |
|
| 1102 | 1134 |
} |
| 1103 |
|
|
| 1104 |
mNotifyBuilder.setOngoing(persistent); |
|
| 1105 |
mNotifyBuilder.setContentText(message); |
|
| 1106 | ||
| 1107 |
mNotificationManager.notify( |
|
| 1108 |
NOTIFY_ID, |
|
| 1109 |
mNotifyBuilder.getNotification()); |
|
| 1110 | 1135 |
} |
| 1111 | 1136 |
|
| 1112 | 1137 | |
| 1113 |
- |
|