diff --git a/SoniControl/app/src/main/java/at/ac/fhstp/sonicontrol/MainActivity.java b/SoniControl/app/src/main/java/at/ac/fhstp/sonicontrol/MainActivity.java index eea9d05ed7cee67c4f94464c9ba125df17bc2de8..85ad1ebf95b3574593171cb549e0c54e39f9ba50 100644 --- a/SoniControl/app/src/main/java/at/ac/fhstp/sonicontrol/MainActivity.java +++ b/SoniControl/app/src/main/java/at/ac/fhstp/sonicontrol/MainActivity.java @@ -442,7 +442,9 @@ public class MainActivity extends BaseActivity implements Scan.DetectionListener preventiveSpoof = settings.getBoolean(ConfigConstants.SETTING_PREVENTIVE_SPOOFING, ConfigConstants.SETTING_PREVENTIVE_SPOOFING_DEFAULT); if(preventiveSpoof) { NotificationHelper.activateSpoofingStatusNotification(getApplicationContext()); - usedBlockingMethod = locationFinder.blockMicOrSpoof(); + if (usedBlockingMethod == null) { + usedBlockingMethod = locationFinder.blockMicOrSpoof(); + } } boolean gpsEnabled = settings.getBoolean(ConfigConstants.SETTING_GPS, ConfigConstants.SETTING_GPS_DEFAULT); @@ -732,19 +734,54 @@ public class MainActivity extends BaseActivity implements Scan.DetectionListener state = StateEnum.ON_HOLD; } + Intent intent = getIntent(); switch (state) { case ON_HOLD: NotificationHelper.activateOnHoldStatusNotification(getApplicationContext()); setGUIStateStopped(); break; case JAMMING: - NotificationHelper.activateSpoofingStatusNotification(getApplicationContext()); setGUIStateStarted(); + NotificationHelper.activateSpoofingStatusNotification(getApplicationContext()); + + if (intent.hasExtra(ConfigConstants.EXTRA_TECHNOLOGY_DETECTED)) { + //TODO: We might use directly the "lastDetectedTechnology", not using Extras ? + + Technology technology = (Technology) intent.getExtras().get(ConfigConstants.EXTRA_TECHNOLOGY_DETECTED); + if (technology != null) { + activateAlert(technology); + intent.removeExtra(ConfigConstants.EXTRA_TECHNOLOGY_DETECTED); + } + } + else if (detectionPendingIntent != null) { + if (sigType != null) { + activateAlert(sigType); + } + else { + // in case the Activity was destroyed + String storedTechnology = sp.getString("lastDetectedTechnology", null); + if (storedTechnology != null) { + Technology lastDetectedTechnology = null; + try { + lastDetectedTechnology = Technology.fromString(storedTechnology); + } + catch (IllegalArgumentException e) { + //Log.d(TAG, "onResume: " + e.getMessage()); + } + if (lastDetectedTechnology != null) { + activateAlert(lastDetectedTechnology); + } + else { + //Log.d(TAG, "onResume: Technology not stored correctly ?"); + } + } + } + } + break; case SCANNING: setGUIStateStarted(); - Intent intent = getIntent(); if (intent.hasExtra(ConfigConstants.EXTRA_TECHNOLOGY_DETECTED)) { //TODO: We might use directly the "lastDetectedTechnology", not using Extras ? diff --git a/SoniControl/app/src/main/java/at/ac/fhstp/sonicontrol/NoiseGenerator.java b/SoniControl/app/src/main/java/at/ac/fhstp/sonicontrol/NoiseGenerator.java index df0acf37898a9efd5d745ef0ccc463bd17726aed..2a1c29f9a196c51167c0c3f709c76a7ba65a089e 100644 --- a/SoniControl/app/src/main/java/at/ac/fhstp/sonicontrol/NoiseGenerator.java +++ b/SoniControl/app/src/main/java/at/ac/fhstp/sonicontrol/NoiseGenerator.java @@ -322,8 +322,13 @@ public class NoiseGenerator { } public void setGeneratedPlayerToNull(){ - generatedWhitenoisePlayer.release(); //release the player resources - audioTrack.release(); //release the player resources + if(generatedWhitenoisePlayer!=null){ + generatedWhitenoisePlayer.release(); + } //release the player resources + /*if(audioTrack!=null){ + audioTrack.release(); + } //release the player resources + */ generatedWhitenoisePlayer = null; //set the player to null audioTrack = null; //set the player to null } diff --git a/SoniControl/app/src/main/java/at/ac/fhstp/sonicontrol/Spoofer.java b/SoniControl/app/src/main/java/at/ac/fhstp/sonicontrol/Spoofer.java index a396b62124f814439b28de0c0199a293e6ac24c3..9eedc3fc232f141b0ac93b923eaf4304ce44342b 100644 --- a/SoniControl/app/src/main/java/at/ac/fhstp/sonicontrol/Spoofer.java +++ b/SoniControl/app/src/main/java/at/ac/fhstp/sonicontrol/Spoofer.java @@ -114,7 +114,7 @@ public class Spoofer { AudioManager audioManager = (AudioManager) main.getSystemService(Context.AUDIO_SERVICE); // not used ? int currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_ALARM); //Log.d("Spoofer", "Streamtype: " + String.valueOf(AudioManager.STREAM_MUSIC)); - audioManager.setStreamVolume(3, (int) Math.round((audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) * 0.99D)), 0); + audioManager.setStreamVolume(3, (int) Math.round((audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) * 0.75D)), 0); if (playingHandler) { playtime = genNoise.getPlayertime(); //get the playertime depending on the generated whitenoise