mip-it il y a 10 ans
Parent
commit
fd29e6f079

BIN
bin/classes.dex


BIN
bin/classes/de/tudarmstadt/informatik/hostage/HoneyService$LocalBinder.class


BIN
bin/classes/de/tudarmstadt/informatik/hostage/HoneyService.class


BIN
bin/classes/de/tudarmstadt/informatik/hostage/ui/MainActivity$1.class


BIN
bin/classes/de/tudarmstadt/informatik/hostage/ui/MainActivity$2.class


BIN
bin/classes/de/tudarmstadt/informatik/hostage/ui/MainActivity$3.class


BIN
bin/classes/de/tudarmstadt/informatik/hostage/ui/MainActivity$4.class


BIN
bin/classes/de/tudarmstadt/informatik/hostage/ui/MainActivity$5.class


BIN
bin/classes/de/tudarmstadt/informatik/hostage/ui/MainActivity.class


BIN
bin/hostage.apk


+ 27 - 0
src/de/tudarmstadt/informatik/hostage/HoneyService.java

@@ -3,10 +3,15 @@ package de.tudarmstadt.informatik.hostage;
 import java.util.ArrayList;
 import java.util.List;
 
+import android.app.NotificationManager;
+import android.app.PendingIntent;
 import android.app.Service;
+import android.content.Context;
 import android.content.Intent;
 import android.os.Binder;
 import android.os.IBinder;
+import android.support.v4.app.NotificationCompat;
+import android.support.v4.app.TaskStackBuilder;
 import android.support.v4.content.LocalBroadcastManager;
 import de.tudarmstadt.informatik.hostage.logging.FileLogger;
 import de.tudarmstadt.informatik.hostage.logging.Logger;
@@ -44,6 +49,7 @@ public class HoneyService extends Service {
 	public void onCreate() {
 		super.onCreate();
 		log = new FileLogger(getApplicationContext());
+		createNotification();
 		for (Protocol protocol : getProtocolArray()) {
 			listeners.add(new HoneyListener(this, protocol));
 		}
@@ -51,10 +57,31 @@ public class HoneyService extends Service {
 
 	@Override
 	public void onDestroy() {
+		cancelNotification();
 		log.close();
 		super.onDestroy();
 	}
 
+	private void createNotification() {
+		NotificationCompat.Builder builder = new NotificationCompat.Builder(
+				this).setSmallIcon(R.drawable.ic_launcher)
+				.setContentTitle(getString(R.string.app_name))
+				.setContentText("Honeypot up and running!");
+		TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
+		stackBuilder.addParentStack(MainActivity.class);
+		stackBuilder.addNextIntent(new Intent(this, MainActivity.class));
+		PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
+				PendingIntent.FLAG_UPDATE_CURRENT);
+		builder.setContentIntent(resultPendingIntent);
+		NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+		mNotificationManager.notify(1, builder.build());
+	}
+
+	private void cancelNotification() {
+		NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+		mNotificationManager.cancel(1);
+	}
+
 	private ArrayList<Protocol> getProtocolArray() {
 		String[] protocols = getResources().getStringArray(R.array.protocols);
 		String packageName = Protocol.class.getPackage().getName();

+ 35 - 13
src/de/tudarmstadt/informatik/hostage/ui/MainActivity.java

@@ -57,13 +57,13 @@ public class MainActivity extends Activity {
 	private ListView listView;
 	private ListViewAdapter adapter;
 
+	private boolean running;
+
 	@Override
 	protected void onCreate(Bundle savedInstanceState) {
 		super.onCreate(savedInstanceState);
 		setContentView(R.layout.activity_main);
 
-		startService(getServiceIntent());
-
 		initViewAnimator();
 		initListView();
 	}
@@ -78,13 +78,17 @@ public class MainActivity extends Activity {
 	protected void onStart() {
 		super.onStart();
 		registerReceiver();
-		bindService(getServiceIntent(), mConnection, BIND_AUTO_CREATE);
+		if (isServiceRunning()) {
+			bindService(getServiceIntent(), mConnection, BIND_ABOVE_CLIENT);
+		}
 	}
 
 	@Override
 	protected void onStop() {
 		super.onStop();
-		unbindService(mConnection);
+		if (isServiceRunning()) {
+			unbindService(mConnection);
+		}
 		unregisterReceiver();
 	}
 
@@ -95,18 +99,24 @@ public class MainActivity extends Activity {
 
 	public void buttonOnOffClick(View view) {
 		if (((ToggleButton) view).isChecked()) {
-			if (isParanoid()) {
-				mService.startListeners();
-			} else {
-				mService.startListener("SMB");
-			}
-			findViewById(R.id.checkBoxParanoid).setEnabled(false);
+			startAndBind();
 		} else {
-			mService.stopListeners();
-			findViewById(R.id.checkBoxParanoid).setEnabled(true);
+			stopAndUnbind();
+			running = false;
 		}
 	}
 
+	private void startAndBind() {
+		startService(getServiceIntent());
+		bindService(getServiceIntent(), mConnection, BIND_ABOVE_CLIENT);
+	}
+
+	private void stopAndUnbind() {
+		mService.stopListeners();
+		unbindService(mConnection);
+		stopService(getServiceIntent());
+	}
+
 	private boolean isParanoid() {
 		return ((CheckBox) findViewById(R.id.checkBoxParanoid)).isChecked();
 	}
@@ -152,7 +162,9 @@ public class MainActivity extends Activity {
 					int position, long id) {
 				String protocolName = ((HashMap<String, String>) adapter
 						.getItem(position)).get("protocol");
-				mService.toggleListener(protocolName);
+				if (isServiceRunning()) {
+					mService.toggleListener(protocolName);
+				}
 			}
 
 		});
@@ -210,6 +222,15 @@ public class MainActivity extends Activity {
 		@Override
 		public void onServiceConnected(ComponentName name, IBinder service) {
 			mService = ((LocalBinder) service).getService();
+			if (!running) {
+				if (isParanoid()) {
+					mService.startListeners();
+				} else {
+					mService.startListener("SMB");
+				}
+			}
+			running = true;
+			updateUI();
 		}
 
 		@Override
@@ -234,6 +255,7 @@ public class MainActivity extends Activity {
 		public void onReceive(Context context, Intent intent) {
 			updateUI();
 		}
+
 	};
 
 	private void updateUI() {