Alexander Brakowski 11 年之前
父節點
當前提交
3b53634df7

+ 0 - 22
native/Makefile~

@@ -1,22 +0,0 @@
-arm: CC = arm-linux-androideabi-gcc
-x86: CC = i686-linux-android-gcc
-mips: CC = mipsel-linux-android-gcc
-CFLAGS = -Wall -g
-LDFLAGS = -llog
-SRC = p.c
-OBJ = $(SRC:.c=.o)
-EXE = p
-
-arm x86 mips: $(SRC) $(EXE)
-
-$(EXE): $(OBJ)
-	$(CC) -o $@ $^ $(LDFLAGS)
-
-%.o: %.c
-	$(CC) -o $@ -c $< $(CFLAGS)
-
-clean:
-	rm -f *.o $(EXE)
-
-install:
-	adb push p /data/local

二進制
native/bind.o


+ 31 - 23
src/com/echo/holographlibrary/LineGraph.java

@@ -48,7 +48,7 @@ public class LineGraph extends View {
         public String convertDataForY_Position(double y);
     }
 
-    private final static int AXIS_LABEL_FONT_SIZE = 10;
+    private final static int AXIS_LABEL_FONT_SIZE = 8;
 
     private ArrayList<Line> lines = new ArrayList<Line>();
 	Paint paint = new Paint();
@@ -64,8 +64,8 @@ public class LineGraph extends View {
 	private Bitmap fullImage;
 	private boolean shouldUpdate = false;
 
-    static final float bottomPadding = 50, topPadding = 10;
-    static final float leftPadding = 50, rightPadding = 10;
+    static final float bottomPadding = 40, topPadding = 16;
+    static final float leftPadding = 50, rightPadding = 16;
     static final float sidePadding = rightPadding + leftPadding;
 
     private float xAxisStep = 4;
@@ -361,13 +361,12 @@ public class LineGraph extends View {
 	        // DRAW THE BACKGROUND
             //this.drawBackground(canvas);
 
+            paint.setAntiAlias(true);
+
             // DRAW THE AXIS
             this.drawAxis(canvas);
 
 
-            paint.reset();
-	        paint.setAntiAlias(true);
-
             // DRAW LINES
 			for (Line line : lines){
 				int count = 0;
@@ -445,20 +444,16 @@ public class LineGraph extends View {
 		}
 		
 		ca.drawBitmap(fullImage, 0, 0, null);
-		
-		
+
 	}
 
     private void drawAxis(Canvas canvas){
-        paint.reset();
+        //double maxX = getMaxLimX();
+        //double minX = getMinLimX();
+        //float usableWidth = getWidth() - 2*sidePadding;
+        //float usableHeight = getHeight() - bottomPadding - topPadding;
 
-        double maxX = getMaxLimX();
-        double minX = getMinLimX();
-
-        float usableWidth = getWidth() - 2*sidePadding;
-        float usableHeight = getHeight() - bottomPadding - topPadding;
-
-        float yPixels = getHeight() - (bottomPadding*(4.f/5.f));
+        float yPixels = getHeight() - (bottomPadding - (10));
 
         // DRAW SEPERATOR
         paint.setColor(Color.BLACK);
@@ -470,8 +465,22 @@ public class LineGraph extends View {
         canvas.drawLine(leftPadding ,topPadding, leftPadding, yPixels, paint);
 
         paint.setAlpha(255);
+
+        this.drawAxisLabel(canvas);
+    }
+
+
+    private void drawAxisLabel(Canvas canvas){
         this.paint.setTextSize(AXIS_LABEL_FONT_SIZE * mContext.getResources().getDisplayMetrics().scaledDensity);
 
+        double maxX = getMaxLimX();
+        double minX = getMinLimX();
+
+        float usableWidth = getWidth() - 2*sidePadding;
+        float usableHeight = getHeight() - bottomPadding - topPadding;
+        float yPixels = getHeight() - (bottomPadding - (10));
+
+
         // Draw y-axis label text
         double step = Math.max(1., (maxY - minY) / (Math.max(1., yAxisStep)));
         double v = 0;
@@ -485,12 +494,11 @@ public class LineGraph extends View {
             canvas.drawText(title, 5.f ,(float)newYPixels + (textwidth/2), this.paint);
 
             v+=step;
-            //value+=skippedValue;
         }
 
+        this.paint.setTextSize(AXIS_LABEL_FONT_SIZE * mContext.getResources().getDisplayMetrics().scaledDensity);
+
         // Draw x-axis label text
-        //value = minX;
-        //skippedValue = (maxX - minX ) / (Math.max(1,xAxisStep));
         step = Math.max(1, (maxX - minX) / (Math.max(1, xAxisStep)));
 
         for (double x = minX; x <= maxX; x+=step){
@@ -500,12 +508,12 @@ public class LineGraph extends View {
             canvas.drawLine((float)newXPixels,(float) yPixels + 5,(float) newXPixels,(float) yPixels, paint);
             String title = this.getX_AxisTitle(x);
             float textwidth = (this.paint.measureText(title));
-            //this.paint.setTextSize(AXIS_LABEL_FONT_SIZE * mContext.getResources().getDisplayMetrics().scaledDensity);
-            canvas.drawText(title,(float) newXPixels - (textwidth/2),(float) yPixels + (bottomPadding / 2), this.paint);
 
-            //value+=skippedValue;
+            float x_Coord = Math.max(0.f, (float) (newXPixels - (textwidth / 2)));
+            x_Coord = Math.min(x_Coord, getWidth() - rightPadding);
+            float y_Coord =  (float) (yPixels + ((bottomPadding - 10) / 1));
+            canvas.drawText(title, x_Coord , y_Coord, this.paint);
         }
-        paint.reset();
     }
 
     private void drawBackground(Canvas canvas){

+ 82 - 8
src/de/tudarmstadt/informatik/hostage/ui2/adapter/ServicesListAdapter.java

@@ -15,6 +15,8 @@ import android.widget.Switch;
 import android.widget.TextView;
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
+import de.tudarmstadt.informatik.hostage.model.Profile;
+import de.tudarmstadt.informatik.hostage.persistence.ProfileManager;
 import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 import de.tudarmstadt.informatik.hostage.ui2.model.ServicesListItem;
 
@@ -30,6 +32,8 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
     private Context mActivity;
     private Switch mServicesSwitch;
     private CompoundButton.OnCheckedChangeListener mListener;
+    private Profile mProfile;
+    private Integer[] mGhostPorts;
 
     /**
      * constructor
@@ -99,7 +103,7 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
                 new CompoundButton.OnCheckedChangeListener() {
                     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                         ServicesListItem item = (ServicesListItem) buttonView.getTag();
-
+                        mProfile = ProfileManager.getInstance().getCurrentActivatedProfile();
                         if (!HelperUtils.isWifiConnected(mActivity)) {
                             new AlertDialog.Builder(mActivity)
                                     .setTitle(R.string.information)
@@ -117,7 +121,29 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
                         } else {
                             //check if switch is set to ON and start the concrete listener for the protocol
                             if (isChecked) {
-                                if (!MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
+                                if(item.protocol.equals("GHOST")){
+                                    if(mProfile.mGhostActive){
+                                        mGhostPorts = mProfile.getGhostPorts();
+
+                                        if(mGhostPorts.length != 0) {
+                                            for(Integer port: mGhostPorts){
+                                                if(!MainActivity.getInstance().getHostageService().isRunning(item.protocol, port)) {
+                                                    MainActivity.getInstance().getHostageService().startListener(item.protocol, port);
+                                                }
+                                            }
+                                            //set the main switch to null, so that he won't react and starts all protocols
+                                            mServicesSwitch.setOnCheckedChangeListener(null);
+                                            mServicesSwitch.setChecked(true);
+                                            mServicesSwitch.setOnCheckedChangeListener(mListener);
+
+                                            buttonView.setChecked(true);
+                                        }
+                                    }
+                                    else {
+                                        buttonView.setChecked(false);
+                                    }
+                                }
+                                else if (!MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
                                     MainActivity.getInstance().getHostageService().startListener(item.protocol);
 
                                     //set the main switch to null, so that he won't react and starts all protocols
@@ -125,14 +151,23 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
                                     mServicesSwitch.setChecked(true);
                                     mServicesSwitch.setOnCheckedChangeListener(mListener);
                                     buttonView.setChecked(true);
-                                } else if (MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
+                                } else {
                                     buttonView.setChecked(true);
                                 }
                             } else {
-                                if (MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
-                                    MainActivity.getInstance().getHostageService().stopListener(item.protocol);
-                                }
-                                buttonView.setChecked(false);
+                                   if(item.protocol.equals("GHOST")) {
+                                       mGhostPorts = mProfile.getGhostPorts();
+                                       for(Integer port: mGhostPorts){
+                                           if(MainActivity.getInstance().getHostageService().isRunning("GHOST",port)){
+                                               MainActivity.getInstance().getHostageService().stopListener("GHOST", port);
+                                           }
+                                       }
+                                       buttonView.setChecked(false);
+                                   }
+                                   else if (MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
+                                        MainActivity.getInstance().getHostageService().stopListener(item.protocol);
+                                    }
+                                    buttonView.setChecked(false);
                             }
                         }
                     }
@@ -148,7 +183,46 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
      * @param holder ViewHolder which represents the item in the View
      */
     private void updateStatus(ServicesListItem item, ViewHolder holder) {
-        if (MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
+        if(item.protocol.equals("GHOST")){
+            mProfile = ProfileManager.getInstance().getCurrentActivatedProfile();
+            mGhostPorts = mProfile.getGhostPorts();
+
+            boolean ghostActive = false;
+
+            for(Integer port: mGhostPorts){
+                if(MainActivity.getInstance().getHostageService().isRunning("GHOST",port)){
+                    ghostActive = true;
+                }
+            }
+            if(ghostActive){
+                holder.activated.setChecked(true);
+
+                if (!MainActivity.getInstance().getHostageService().hasProtocolActiveAttacks(item.protocol)) {
+                    if (item.attacks > 0) {
+                        setBackground(holder, R.drawable.services_circle_yellow);
+                    } else {
+                        setBackground(holder, R.drawable.services_circle_green);
+                    }
+
+                } else {
+                    if (MainActivity.getInstance().getHostageService().hasProtocolActiveAttacks(item.protocol)) {
+                        setBackground(holder, R.drawable.services_circle_red);
+                    }
+                }
+
+            } else if (item.attacks > 0) {
+                holder.activated.setChecked(false);
+                setBackground(holder, R.drawable.services_circle_yellow);
+            } else {
+                holder.activated.setChecked(false);
+                setBackground(holder, R.drawable.services_circle);
+            }
+
+
+
+
+        }
+        else if (MainActivity.getInstance().getHostageService().isRunning(item.protocol)) {
             holder.activated.setChecked(true);
             if (!MainActivity.getInstance().getHostageService().hasProtocolActiveAttacks(item.protocol)) {
                 if (item.attacks > 0) {

+ 25 - 2
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ServicesFragment.java

@@ -23,6 +23,8 @@ import de.tudarmstadt.informatik.hostage.Handler;
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
 import de.tudarmstadt.informatik.hostage.deprecated.UglyDbHelper;
+import de.tudarmstadt.informatik.hostage.model.Profile;
+import de.tudarmstadt.informatik.hostage.persistence.ProfileManager;
 import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 import de.tudarmstadt.informatik.hostage.ui2.adapter.ServicesListAdapter;
 import de.tudarmstadt.informatik.hostage.ui2.model.ServicesListItem;
@@ -55,6 +57,9 @@ public class ServicesFragment extends Fragment {
 
     private boolean mReceiverRegistered = false;
 
+    private Profile mProfile;
+    private Integer[] mGhostPorts;
+
     public ServicesFragment() {
     }
 
@@ -167,6 +172,7 @@ public class ServicesFragment extends Fragment {
         if (switchChangeListener == null) {
             switchChangeListener = new CompoundButton.OnCheckedChangeListener() {
                 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+                    mProfile = ProfileManager.getInstance().getCurrentActivatedProfile();
                     if (!HelperUtils.isWifiConnected(getActivity())) {
                         new AlertDialog.Builder(getActivity())
                                 .setTitle(R.string.information)
@@ -187,8 +193,25 @@ public class ServicesFragment extends Fragment {
                         if (MainActivity.getInstance().isServiceBound()) {
                             if (isChecked) {
                                 for (String protocol : protocols) {
-                                    if (!MainActivity.getInstance().getHostageService().isRunning(protocol)) {
-                                        MainActivity.getInstance().getHostageService().startListener(protocol);
+                                    if(!protocol.equals("GHOST")) {
+                                         if (!MainActivity.getInstance().getHostageService().isRunning(protocol)) {
+                                             MainActivity.getInstance().getHostageService().startListener(protocol);
+                                         }
+                                    }
+                                    else {
+                                        if(mProfile.mGhostActive){
+
+                                            mGhostPorts = mProfile.getGhostPorts();
+                                            if (mGhostPorts.length != 0)  {
+                                                for (Integer port : mGhostPorts) {
+                                                    if(!MainActivity.getInstance().getHostageService().isRunning("GHOST", port)) {
+                                                        MainActivity.getInstance().getHostageService().startListener("GHOST", port);
+                                                    }
+                                                }
+                                            }
+
+
+                                        }
                                     }
                                 }
                                 setStateActive();