|
@@ -51,22 +51,25 @@ import de.tudarmstadt.informatik.hostage.ui.activity.MainActivity;
|
|
|
|
|
|
/**
|
|
|
* Helper class with some static methods for general usage.
|
|
|
- *
|
|
|
+ *
|
|
|
* @author Lars Pandikow
|
|
|
* @author Wulf Pfeiffer
|
|
|
- *
|
|
|
+ *
|
|
|
*/
|
|
|
public final class HelperUtils {
|
|
|
|
|
|
-
|
|
|
- public static boolean isFileAlert() {
|
|
|
- return fileAlert;
|
|
|
+ public static String getFilePath() {
|
|
|
+ return filePath;
|
|
|
}
|
|
|
|
|
|
- public static void setFileAlert(boolean fileAlert) {
|
|
|
- HelperUtils.fileAlert = fileAlert;
|
|
|
+ public static void setFilePath(String filePath) {
|
|
|
+ HelperUtils.filePath = filePath;
|
|
|
}
|
|
|
|
|
|
+ public static String filePath;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
public static String getFileName() {
|
|
|
return fileName;
|
|
|
}
|
|
@@ -75,15 +78,25 @@ public final class HelperUtils {
|
|
|
HelperUtils.fileName = fileName;
|
|
|
}
|
|
|
|
|
|
- public static boolean fileAlert = false;
|
|
|
+
|
|
|
public static String fileName;
|
|
|
|
|
|
+ public static String getFileMD5() {
|
|
|
+ return fileMD5;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void setFileMD5(String fileMD5) {
|
|
|
+ HelperUtils.fileMD5 = fileMD5;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String fileMD5;
|
|
|
+
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Converts a byte array into a hexadecimal String, e.g. {0x00, 0x01} to
|
|
|
* "00, 01".
|
|
|
- *
|
|
|
+ *
|
|
|
* @param bytes
|
|
|
* that will be converted.
|
|
|
* @return converted String.
|
|
@@ -105,7 +118,7 @@ public final class HelperUtils {
|
|
|
/**
|
|
|
* Converts a byte[] to a String, but only characters in ASCII between 32
|
|
|
* and 127
|
|
|
- *
|
|
|
+ *
|
|
|
* @param bytes
|
|
|
* that are converted
|
|
|
* @return converted String
|
|
@@ -113,9 +126,9 @@ public final class HelperUtils {
|
|
|
public static String byteToStr(byte[] bytes) {
|
|
|
int size = 0;
|
|
|
for(byte b : bytes) {
|
|
|
- if(isLetter((char) b)) {
|
|
|
- size++;
|
|
|
- }
|
|
|
+ if(isLetter((char) b)) {
|
|
|
+ size++;
|
|
|
+ }
|
|
|
}
|
|
|
char[] chars = new char[size];
|
|
|
for (int i = 0, j = 0; i < bytes.length && j < size; i++) {
|
|
@@ -129,7 +142,7 @@ public final class HelperUtils {
|
|
|
|
|
|
/**
|
|
|
* Concatenates several byte arrays.
|
|
|
- *
|
|
|
+ *
|
|
|
* @param bytes
|
|
|
* The byte arrays.
|
|
|
* @return A single byte arrays containing all the bytes from the given
|
|
@@ -156,7 +169,7 @@ public final class HelperUtils {
|
|
|
|
|
|
/**
|
|
|
* Puts a 0x00 byte between each byte in a byte array.
|
|
|
- *
|
|
|
+ *
|
|
|
* @param bytes
|
|
|
* that need to be filled with 0x00.
|
|
|
* @return filled byte array.
|
|
@@ -173,7 +186,7 @@ public final class HelperUtils {
|
|
|
/**
|
|
|
* Puts a 0x00 byte between each byte and another 2 0x00 bytes at the end of
|
|
|
* a byte array.
|
|
|
- *
|
|
|
+ *
|
|
|
* @param bytes
|
|
|
* that need to be filled with 0x00.
|
|
|
* @return filled byte array.
|
|
@@ -189,7 +202,7 @@ public final class HelperUtils {
|
|
|
|
|
|
/**
|
|
|
* Gets BSSID of the wireless network.
|
|
|
- *
|
|
|
+ *
|
|
|
* @param context
|
|
|
* Needs a context to get system recourses.
|
|
|
* @return BSSID of wireless network if connected, else null.
|
|
@@ -270,7 +283,7 @@ public final class HelperUtils {
|
|
|
|
|
|
/**
|
|
|
* Gets internal IP address of the device in a wireless network.
|
|
|
- *
|
|
|
+ *
|
|
|
* @param context
|
|
|
* Needs a context to get system recourses.
|
|
|
* @return internal IP of the device in a wireless network if connected,
|
|
@@ -301,7 +314,7 @@ public final class HelperUtils {
|
|
|
|
|
|
/**
|
|
|
* Gets SSID of the wireless network.
|
|
|
- *
|
|
|
+ *
|
|
|
* @param context
|
|
|
* Needs a context to get system recourses
|
|
|
* @return SSID of wireless network if connected, else null.
|
|
@@ -326,10 +339,10 @@ public final class HelperUtils {
|
|
|
}
|
|
|
return ssid;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Gets the mac address of the devicek.
|
|
|
- *
|
|
|
+ *
|
|
|
* @param context
|
|
|
* Needs a context to get system recourses
|
|
|
* @return MAC address of the device.
|
|
@@ -337,16 +350,16 @@ public final class HelperUtils {
|
|
|
public static String getMacAdress(Context context) {
|
|
|
String mac = null;
|
|
|
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
|
|
- WifiInfo connectionInfo = wifiManager.getConnectionInfo();
|
|
|
+ WifiInfo connectionInfo = wifiManager.getConnectionInfo();
|
|
|
mac = connectionInfo.getMacAddress();
|
|
|
return mac;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Produces a random String. The String can be of random length (minimum 1)
|
|
|
* with a maximum length, or it can be forced to have the length that was
|
|
|
* given.
|
|
|
- *
|
|
|
+ *
|
|
|
* @param length
|
|
|
* maximal / forced length of String.
|
|
|
* @param forceLength
|
|
@@ -365,7 +378,7 @@ public final class HelperUtils {
|
|
|
|
|
|
/**
|
|
|
* Converts a String into a byte array, e.g. "00, 01" to {0x00, 0x01}.
|
|
|
- *
|
|
|
+ *
|
|
|
* @param string
|
|
|
* that will be converted.
|
|
|
* @return converted byte array.
|
|
@@ -382,7 +395,7 @@ public final class HelperUtils {
|
|
|
|
|
|
/**
|
|
|
* Generates a random byte[] of a specified size
|
|
|
- *
|
|
|
+ *
|
|
|
* @param size
|
|
|
* of the byte[]
|
|
|
* @return random byte[]
|
|
@@ -397,7 +410,7 @@ public final class HelperUtils {
|
|
|
/**
|
|
|
* Turns around the values of an byte[], e.g. {0x00, 0x01, 0x02} turns into
|
|
|
* {0x02, 0x01, 0x00}.
|
|
|
- *
|
|
|
+ *
|
|
|
* @param bytes
|
|
|
* array that is turned.
|
|
|
* @return turned array.
|
|
@@ -412,7 +425,7 @@ public final class HelperUtils {
|
|
|
|
|
|
/**
|
|
|
* Determines if a character is in ASCII between 32 and 126
|
|
|
- *
|
|
|
+ *
|
|
|
* @param character
|
|
|
* that is checked
|
|
|
* @return true if the character is between 32 and 126, else false
|
|
@@ -444,11 +457,11 @@ public final class HelperUtils {
|
|
|
|
|
|
public static String inetAddressToString(int address) {
|
|
|
return String.valueOf(address & 0xFF) + "."
|
|
|
- + String.valueOf((address >>> 8) & 0xFF) + "."
|
|
|
- + String.valueOf((address >>> 16) & 0xFF) + "."
|
|
|
- + String.valueOf((address >>> 24) & 0xFF);
|
|
|
+ + String.valueOf((address >>> 8) & 0xFF) + "."
|
|
|
+ + String.valueOf((address >>> 16) & 0xFF) + "."
|
|
|
+ + String.valueOf((address >>> 24) & 0xFF);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static boolean isWifiConnected(Context context){
|
|
|
if(context == null) return false;
|
|
|
ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
@@ -456,7 +469,7 @@ public final class HelperUtils {
|
|
|
|
|
|
return mWifi.isConnected();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static boolean isNetworkAvailable(Context context) {
|
|
|
if(context == null) return false;
|
|
|
|
|
@@ -465,7 +478,7 @@ public final class HelperUtils {
|
|
|
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
|
|
|
}
|
|
|
|
|
|
- public static int getRedirectedPort(int port){
|
|
|
- return port + 1024 + 27113;
|
|
|
- }
|
|
|
+ public static int getRedirectedPort(int port){
|
|
|
+ return port + 1024 + 27113;
|
|
|
+ }
|
|
|
}
|