Skip to content

Commit

Permalink
Fixed error when deactivate monitoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
irinil committed Aug 11, 2020
1 parent 9cc8acc commit 31e1c9d
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 123 deletions.
4 changes: 2 additions & 2 deletions src/main/java/de/tudarmstadt/informatik/hostage/Hostage.java
Expand Up @@ -124,7 +124,7 @@ protected Integer doInBackground(String... strings) {

@Override
protected void onPostExecute(Integer result) {
prefix=result;
prefix = result;
}
}

Expand Down Expand Up @@ -329,7 +329,7 @@ public void onCreate() {

private void loadConnectionInfo(){
try {
TimeUnit.MILLISECONDS.sleep(30);
TimeUnit.MILLISECONDS.sleep(70);
updateConnectionInfo();
} catch (InterruptedException e) {
e.printStackTrace();
Expand Down
Expand Up @@ -49,7 +49,7 @@ public class Profile implements JSONSerializable<Profile> {
@Transient
public boolean mIsRandom = false;
@Transient
public HashMap<String, Boolean> mActiveProtocols = new HashMap<String, Boolean>();
public HashMap<String, Boolean> mActiveProtocols = new HashMap<>();

@Transient
public String mGhostPorts = "";
Expand Down Expand Up @@ -150,7 +150,7 @@ public boolean isProtocolActive(String protocol){
}

public List<String> getActiveProtocols(){
List<String> list = new LinkedList<String>();
List<String> list = new LinkedList<>();
for(Map.Entry<String, Boolean> entry: this.mActiveProtocols.entrySet()){
if(entry.getValue()){
list.add(entry.getKey());
Expand Down
Expand Up @@ -160,8 +160,11 @@ public void loadData() throws Exception {
}
loadProfiles(sb,fbr);


} catch (IOException | JSONException e) {
e.printStackTrace();
} finally {
fillWithDefaultData();
}
}

Expand Down Expand Up @@ -240,7 +243,7 @@ public void persistData(){
* @return a list that holds all the profiles
*/
public List<Profile> getProfilesList() throws Exception {
return new ArrayList<Profile>(getProfilesCollection());
return new ArrayList<>(getProfilesCollection());
}

/**
Expand Down Expand Up @@ -269,7 +272,7 @@ public Map<Integer, Profile> getMapProfiles(){
* @param profile the profile to randomize the protocols for
*/
public void randomizeProtocols(Profile profile){
LinkedList<String> protocols = new LinkedList<String>(Arrays.asList(MainActivity.getContext().getResources().getStringArray(R.array.protocols)));
LinkedList<String> protocols = new LinkedList<>(Arrays.asList(MainActivity.getContext().getResources().getStringArray(R.array.protocols)));
profile.mActiveProtocols.clear();

Random rand = new Random();
Expand Down
Expand Up @@ -159,7 +159,10 @@ public CoapClient getSimpleClient(InetSocketAddress serverAddress, CoapServer se
* Stops the server and closes the port
*/
public static void serverStop(){
server.stop();
if(serverStarted) {
server.stop();
serverStarted = false;
}
}

}
Expand Up @@ -267,12 +267,6 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_drawer_main);
getLocationData();

try {
mProfileManager = ProfileManager.getInstance();
} catch (Exception e) {
e.printStackTrace();
}

// init threat indicator animation
ThreatIndicatorGLRenderer.setThreatLevel(ThreatIndicatorGLRenderer.ThreatLevel.NOT_MONITORING);

Expand Down Expand Up @@ -346,7 +340,6 @@ public void onDrawerOpened(View drawerView) {
onFirstRun();
}


if (savedInstanceState == null) {
// on first time display view for first nav item
displayView(0);
Expand Down Expand Up @@ -793,8 +786,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
}

@Override
public void onRequestPermissionsResult(int requestCode,
String[] permissions, int[] grantResults) {
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == MY_PERMISSIONS_REQUEST_WRITE_STORAGE) {
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Expand Down

0 comments on commit 31e1c9d

Please sign in to comment.