Browse Source

small fixes, code sucks

Mihai Plasoianu 10 years ago
parent
commit
ed17a68c87

+ 5 - 3
src/de/tudarmstadt/informatik/hostage/Hostage.java

@@ -431,9 +431,10 @@ public class Hostage extends Service {
 		builder = new NotificationCompat.Builder(this).setContentTitle(getString(R.string.app_name)).setTicker("Honeypot under attack!")
 				.setContentText("Honeypot under attack!").setSmallIcon(R.drawable.ic_service_red).setAutoCancel(true).setWhen(System.currentTimeMillis())
 				.setSound(Uri.parse(strRingtonePreference));
+		Intent launchIntent = new Intent(getApplicationContext(), MainActivity.class);
 		TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
 		stackBuilder.addParentStack(MainActivity.class);
-		stackBuilder.addNextIntent(new Intent(this, MainActivity.class));
+		stackBuilder.addNextIntent(launchIntent);
 		PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
 		builder.setContentIntent(resultPendingIntent);
 		if (defaultPref.getBoolean("pref_vibration", false)) {
@@ -441,7 +442,7 @@ public class Hostage extends Service {
 		}
 
 		NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
-		mNotificationManager.notify(2, builder.build());
+		mNotificationManager.notify(1, builder.build());
 	}
 
 	/**
@@ -508,9 +509,10 @@ public class Hostage extends Service {
 			builder.setSmallIcon(R.drawable.ic_service_green);
 			builder.setContentText("Everything looks fine!");
 		}
+		Intent launchIntent = new Intent(getApplicationContext(), MainActivity.class);
 		TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
 		stackBuilder.addParentStack(MainActivity.class);
-		stackBuilder.addNextIntent(new Intent(this, MainActivity.class));
+		stackBuilder.addNextIntent(launchIntent);
 		PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
 		builder.setContentIntent(resultPendingIntent);
 		builder.setOngoing(true);

+ 1 - 1
src/de/tudarmstadt/informatik/hostage/net/MyDatagramSocketFactory.java

@@ -16,7 +16,7 @@ public class MyDatagramSocketFactory {
 		DatagramSocket socket = null;
 		if (port > 1023) {
 			socket = new DatagramSocket(port);
-		} else if (Device.isPPInstalled()) {
+		} else if (Device.isPorthackInstalled()) {
 			FileDescriptor fd = new PrivilegedPort(TYPE.UDP, port).getFD();
 			socket = new DatagramSocket();
 			try {

+ 1 - 1
src/de/tudarmstadt/informatik/hostage/net/MyServerSocketFactory.java

@@ -24,7 +24,7 @@ public class MyServerSocketFactory extends ServerSocketFactory {
 			socket = new ServerSocket();
 			socket.setReuseAddress(true);
 			socket.bind(new InetSocketAddress(port));
-		} else if (Device.isPPInstalled()) {
+		} else if (Device.isPorthackInstalled()) {
 			FileDescriptor fd = new PrivilegedPort(TYPE.TCP, port).getFD();
 			socket = new ServerSocket();
 			try {

+ 13 - 6
src/de/tudarmstadt/informatik/hostage/provider/HostageContentProvider.java

@@ -22,12 +22,17 @@ public class HostageContentProvider extends ContentProvider {
 	public static final Uri CONTENT_URI_ATTACK = Uri.parse("content://" + AUTHORITY + "/attack");
 	public static final Uri CONTENT_URI_PACKET = Uri.parse("content://" + AUTHORITY + "/packet");
 
-	private static final int NETWORK_ALL = 1;
-	private static final int NETWORK_ONE = 2;
-	private static final int ATTACK_ALL = 3;
-	private static final int ATTACK_ONE = 4;
-	private static final int PACKET_ALL = 5;
-	private static final int PACKET_ONE = 6;
+	public static final Uri CONTENT_URI_RECORD_OVERVIEW = Uri.parse("content://" + AUTHORITY + "/record-overview");
+
+	private static final int NETWORK_ALL = 11;
+	private static final int NETWORK_ONE = 12;
+	private static final int ATTACK_ALL = 21;
+	private static final int ATTACK_ONE = 22;
+	private static final int PACKET_ALL = 31;
+	private static final int PACKET_ONE = 32;
+
+	private static final int NETWORK_OVERVIEW_ALL = 101;
+	private static final int NETWORK_OVERVIEW_ONE = 102;
 
 	private static final UriMatcher uriMatcher;
 
@@ -39,6 +44,8 @@ public class HostageContentProvider extends ContentProvider {
 		uriMatcher.addURI(AUTHORITY, "attack/#", ATTACK_ONE);
 		uriMatcher.addURI(AUTHORITY, "packet", PACKET_ALL);
 		uriMatcher.addURI(AUTHORITY, "packet/#", PACKET_ONE);
+		uriMatcher.addURI(AUTHORITY, "record-overview", NETWORK_OVERVIEW_ALL);
+		uriMatcher.addURI(AUTHORITY, "record-overview/#", NETWORK_OVERVIEW_ONE);
 	}
 
 	private HostageDBOpenHelper mDBOpenHelper;

+ 1 - 1
src/de/tudarmstadt/informatik/hostage/system/Device.java

@@ -52,7 +52,7 @@ public class Device {
 		return root;
 	}
 
-	public static boolean isPPInstalled() {
+	public static boolean isPorthackInstalled() {
 		while (!initialized)
 			;
 		return pp;

+ 6 - 38
src/de/tudarmstadt/informatik/hostage/ui2/activity/MainActivity.java

@@ -1,7 +1,5 @@
 package de.tudarmstadt.informatik.hostage.ui2.activity;
 
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.HashMap;
 
@@ -55,10 +53,6 @@ import de.tudarmstadt.informatik.hostage.ui2.model.DrawerListItem;
 public class MainActivity extends Activity {
 	public static volatile Context context;
 
-	public static boolean isRooted = false;
-
-	public static boolean porthackInstalled = false;
-
 	/** singleton instance of the MainActivity **/
 	private static MainActivity sInstance = null;
 
@@ -143,6 +137,12 @@ public class MainActivity extends Activity {
 		}
 	}
 
+	@Override
+	public void onStop() {
+		this.unbindService();
+		super.onStop();
+	}
+
 	@Override
 	protected void onCreate(Bundle savedInstanceState) {
 		super.onCreate(savedInstanceState);
@@ -209,7 +209,6 @@ public class MainActivity extends Activity {
 		};
 		mDrawerLayout.setDrawerListener(mDrawerToggle);
 
-		checkRootAndPorthack();
 		startAndBind();
 
 		if (savedInstanceState == null) {
@@ -515,37 +514,6 @@ public class MainActivity extends Activity {
 		return this.mDisplayedFragment;
 	}
 
-	/**
-	 * Checks if the phone ist rooted and if porthack is installed. Sets flags
-	 * {@link this.isRooted} and {@link this.porthackInstalled}
-	 */
-	private void checkRootAndPorthack() {
-		isRooted = false;
-		porthackInstalled = false;
-		Process p;
-		try {
-			String found = "Found";
-			String notFound = "Not found";
-			String command = "[ -f /data/local/p ] && echo " + found + " || echo " + notFound;
-			p = Runtime.getRuntime().exec(new String[] { "su", "-c", command });
-			BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
-			/*
-			 * int av = byte[] b = new byte[av]; if (av != 0) { in.read(b); }
-			 */
-			String echoResponse = in.readLine();
-			Log.i("MainAc", echoResponse);
-			if (echoResponse.equals(found)) {
-				isRooted = true;
-				porthackInstalled = true;
-			} else if (echoResponse.equals(notFound)) {
-				isRooted = true;
-			}
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-		Log.i("MainAc", "Rooted: " + isRooted + " Porthack: " + porthackInstalled);
-	}
-
 	public Hostage getHostageService() {
 		return this.mHoneyService;
 	}

+ 1 - 2
src/de/tudarmstadt/informatik/hostage/ui2/fragment/HomeFragment.java

@@ -371,10 +371,9 @@ public class HomeFragment extends Fragment {
 
 	@Override
 	public void onStop() {
-		super.onStop();
-
 		unregisterBroadcastReceiver();
 		// mHomeSwitchConnection.setOnCheckedChangeListener(null);
+		super.onStop();
 	}
 
 	@Override

+ 4 - 6
src/de/tudarmstadt/informatik/hostage/ui2/fragment/SettingsFragment.java

@@ -1,22 +1,20 @@
 package de.tudarmstadt.informatik.hostage.ui2.fragment;
 
-import android.app.Fragment;
 import android.app.FragmentManager;
 import android.os.Bundle;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.TextView;
-
 import de.tudarmstadt.informatik.hostage.R;
-import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
+import de.tudarmstadt.informatik.hostage.system.Device;
 
 /**
  * @author Alexander Brakowski
  * @created 24.02.14 23:37
  */
 public class SettingsFragment extends UpNavigatibleFragment {
-	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
+	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
 		super.onCreateView(inflater, container, savedInstanceState);
 		getActivity().setTitle(getResources().getString(R.string.drawer_settings));
 		View v = inflater.inflate(R.layout.fragment_settings, container, false);
@@ -24,7 +22,7 @@ public class SettingsFragment extends UpNavigatibleFragment {
 		TextView rootedText = (TextView) v.findViewById(R.id.settings_device_rooted);
 		TextView porthackText = (TextView) v.findViewById(R.id.settings_porthack_installed);
 
-		if(MainActivity.isRooted){
+		if (Device.isRooted()) {
 			rootedText.setText(R.string.yes);
 			rootedText.setTextColor(getResources().getColor(R.color.holo_dark_green));
 		} else {
@@ -32,7 +30,7 @@ public class SettingsFragment extends UpNavigatibleFragment {
 			rootedText.setTextColor(getResources().getColor(R.color.holo_red));
 		}
 
-		if(MainActivity.porthackInstalled){
+		if (Device.isPorthackInstalled()) {
 			porthackText.setText(R.string.yes);
 			porthackText.setTextColor(getResources().getColor(R.color.holo_dark_green));
 		} else {