Browse Source

made speech bubble optional. fixed shader

Fabio Arnold 9 years ago
parent
commit
5e0a9f1ccc

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

@@ -24,6 +24,7 @@ public class Device {
 	private static boolean porthack = false; // porthack installed
 	private static boolean iptables = false; // iptables redirection confirmed working
 
+	// TODO: do asynchronous
     public static void checkCapabilities() {
 		// assume worst case
 		initialized = false;
@@ -53,6 +54,7 @@ public class Device {
 			e.printStackTrace();
 		}
 
+		// TODO: test with various devices
 		if (Build.VERSION.SDK_INT >= 18) { // iptables isn't fully implemented on older versions
 			final String ipTablesList = "iptables -L -n -t nat"; // list all rules in NAT table
 			try {
@@ -76,6 +78,7 @@ public class Device {
 		}
 
 		initialized = true;
+		Log.i("TESTEST", "initialized");
 	}
 
 	public static boolean isRooted() {

+ 2 - 0
src/de/tudarmstadt/informatik/hostage/ui/fragment/HomeFragment.java

@@ -267,6 +267,8 @@ public class HomeFragment extends Fragment {
 				if (relx < 0.25f || relx > 0.75f) return false;
 				if (rely < 0.25f || rely > 0.75f) return false;
 
+				ThreatIndicatorGLRenderer.showSpeechBubble = true;
+
 				String message = "???";
 				switch (mThreatLevel) {
 					case NOT_MONITORING:

+ 45 - 38
src/de/tudarmstadt/informatik/hostage/ui/fragment/opengl/ThreatIndicatorGLRenderer.java

@@ -49,6 +49,8 @@ public class ThreatIndicatorGLRenderer implements Renderer {
 		mNextThreatLevel = threatLevel;
 	}
 
+	public static boolean showSpeechBubble = false;
+
 	/**
 	 * Match the background color of the view holding this renderer
 	 * @param color 32 bit integer encoding the color
@@ -158,7 +160,8 @@ public class ThreatIndicatorGLRenderer implements Renderer {
 				+ "	vertexTexCoord = texCoord;"
 				+ "	gl_Position = vec4(2.0 * (position / resolution) - 1.0, 0.0, 1.0);"
 				+ "}",
-				  "uniform sampler2D colormap;" // fragment
+				  "precision mediump float;"
+				+ "uniform sampler2D colormap;" // fragment
 				+ "uniform vec3 color;"
 				+ "varying vec2 vertexTexCoord;"
 				+ "void main() {"
@@ -316,44 +319,48 @@ public class ThreatIndicatorGLRenderer implements Renderer {
 		updateAndroidAndBee();
 		drawAndroidAndBee(animTime);
 
-		GLES20.glDisable(GLES20.GL_DEPTH_TEST);
-		GLES20.glEnable(GLES20.GL_BLEND);
-		GLES20.glDisable(GLES20.GL_CULL_FACE);
-		GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
-		GLES20.glUseProgram(mTexturedProgram);
-		int resolutionUniformLoc = GLES20.glGetUniformLocation(mTexturedProgram, "resolution");
-		int textureUniformLoc = GLES20.glGetUniformLocation(mTexturedProgram, "colormap");
-		int colorUniformLoc = GLES20.glGetUniformLocation(mTexturedProgram, "color");
-		GLES20.glUniform2f(resolutionUniformLoc, 1024.0f, 1024.0f);
-		GLES20.glUniform1i(textureUniformLoc, 0);
-		GLES20.glUniform3f(colorUniformLoc, 1.0f, 1.0f, 1.0f);
-		String message = "???";
-		switch (mNextThreatLevel) {
-			case NOT_MONITORING:
-				message = ctx.getString(R.string.honeypot_not_monitoring);
-				break;
-			case NO_THREAT:
-				message = ctx.getString(R.string.honeypot_no_threat);
-				break;
-			case PAST_THREAT:
-				message = ctx.getString(R.string.honeypot_past_threat);
-				break;
-			case LIVE_THREAT:
-				message = ctx.getString(R.string.honeypot_live_threat);
-				break;
+		if (showSpeechBubble) {
+			Log.i("GL", "drawing bubble");
+			GLES20.glDisable(GLES20.GL_DEPTH_TEST);
+			GLES20.glEnable(GLES20.GL_BLEND);
+			GLES20.glDisable(GLES20.GL_CULL_FACE);
+			GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
+			GLES20.glUseProgram(mTexturedProgram);
+			int resolutionUniformLoc = GLES20.glGetUniformLocation(mTexturedProgram, "resolution");
+			int textureUniformLoc = GLES20.glGetUniformLocation(mTexturedProgram, "colormap");
+			int colorUniformLoc = GLES20.glGetUniformLocation(mTexturedProgram, "color");
+			GLES20.glUniform2f(resolutionUniformLoc, 1024.0f, 1024.0f);
+			GLES20.glUniform1i(textureUniformLoc, 0);
+			GLES20.glUniform3f(colorUniformLoc, 1.0f, 1.0f, 1.0f);
+			String message = "???";
+			switch (mNextThreatLevel) {
+				case NOT_MONITORING:
+					message = ctx.getString(R.string.honeypot_not_monitoring);
+					break;
+				case NO_THREAT:
+					message = ctx.getString(R.string.honeypot_no_threat);
+					break;
+				case PAST_THREAT:
+					message = ctx.getString(R.string.honeypot_past_threat);
+					break;
+				case LIVE_THREAT:
+					message = ctx.getString(R.string.honeypot_live_threat);
+					break;
+			}
+			float textWidth = font.getTextWidth(message);
+			float textHeight = 40.0f;
+			float bubbleSize = textWidth + 100.0f;
+			float y = 0.75f * 1024.0f + 32.0f * (float) Math.sin(2.0 * animTime);
+			float x = 0.5f * 1024.0f + 16.0f * (float) Math.cos(1.0 * animTime);
+			drawTexturedQuad(speechBubbleTexture, x - 0.5f * bubbleSize, y - 0.25f * bubbleSize,
+					bubbleSize, 0.5f * bubbleSize);
+			GLES20.glUniform3f(colorUniformLoc, 0.0f, 0.0f, 0.0f);
+			font.drawText(mTexturedProgram, message, x - 0.5f * textWidth,
+					y - 0.5f * textHeight);
+			GLES20.glUseProgram(0);
+			GLES20.glEnable(GLES20.GL_DEPTH_TEST);
+			GLES20.glDisable(GLES20.GL_BLEND);
 		}
-		float textWidth = font.getTextWidth(message);
-		float textHeight = 40.0f;
-		float bubbleSize = textWidth + 100.0f;
-		float y = 0.75f * 1024.0f + 32.0f * (float)Math.sin(2.0*animTime);
-		float x = 0.5f * 1024.0f + 16.0f * (float)Math.cos(1.0*animTime);
-		drawTexturedQuad(speechBubbleTexture, x - 0.5f*bubbleSize, y - 0.25f*bubbleSize, bubbleSize, 0.5f*bubbleSize);
-		GLES20.glUniform3f(colorUniformLoc, 0.0f, 0.0f, 0.0f);
-		font.drawText(mTexturedProgram, message, x - 0.5f*textWidth,
-				y - 0.5f*textHeight);
-		GLES20.glUseProgram(0);
-		GLES20.glEnable(GLES20.GL_DEPTH_TEST);
-		GLES20.glDisable(GLES20.GL_BLEND);
 		
 		long deltaTime = System.currentTimeMillis() - mStartTimeMillis - timeMillis; // time for one frame
 		if (deltaTime < 33) {