|
|
|
|
|
|
|
|
import android.content.Intent; |
|
|
import android.content.Intent; |
|
|
import android.os.Binder; |
|
|
import android.os.Binder; |
|
|
import android.os.IBinder; |
|
|
import android.os.IBinder; |
|
|
|
|
|
import android.util.Log; |
|
|
import android.widget.ImageView; |
|
|
import android.widget.ImageView; |
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull; |
|
|
import androidx.annotation.NonNull; |
|
|
|
|
|
|
|
|
import androidx.camera.core.ExperimentalGetImage; |
|
|
import androidx.camera.core.ExperimentalGetImage; |
|
|
import androidx.lifecycle.LifecycleService; |
|
|
import androidx.lifecycle.LifecycleService; |
|
|
|
|
|
|
|
|
|
|
|
import com.example.ueberwachungssystem.WifiCommunication; |
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
import java.io.File; |
|
|
|
|
|
|
|
|
@ExperimentalGetImage |
|
|
@ExperimentalGetImage |
|
|
|
|
|
|
|
|
public Accelerometer motionDetector = null; |
|
|
public Accelerometer motionDetector = null; |
|
|
public MicrophoneDetector audioDetector = null; |
|
|
public MicrophoneDetector audioDetector = null; |
|
|
|
|
|
|
|
|
|
|
|
public WifiCommunication wifiCommunication; |
|
|
|
|
|
|
|
|
|
|
|
String wifiData; |
|
|
|
|
|
StringBuffer stringBufferWifi = new StringBuffer(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public int onStartCommand(Intent intent, int flags, int startId) { |
|
|
public int onStartCommand(Intent intent, int flags, int startId) { |
|
|
if (isServiceRunning) |
|
|
if (isServiceRunning) |
|
|
return START_NOT_STICKY; |
|
|
return START_NOT_STICKY; |
|
|
|
|
|
|
|
|
|
|
|
/** Wifi Instanz **/ |
|
|
|
|
|
wifiCommunication = new WifiCommunication(1234); |
|
|
|
|
|
wifiCommunication.sendTrue("TEst"); |
|
|
|
|
|
|
|
|
|
|
|
wifiCommunication.setOnConnectionListener(new WifiCommunication.OnConnectionListener() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onConnection(String data) { |
|
|
|
|
|
Log.d("Listener", data); |
|
|
|
|
|
wifiData = data; |
|
|
|
|
|
stringToStringbuffer(data); |
|
|
|
|
|
Log.d("buffer",stringBufferWifi.toString()); |
|
|
|
|
|
passToServiceListener(stringBufferWifi); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
videoDetector.setOnDetectionListener(new Detector.OnDetectionListener() { |
|
|
videoDetector.setOnDetectionListener(new Detector.OnDetectionListener() { |
|
|
@Override |
|
|
@Override |
|
|
public void onDetection(@NonNull DetectionReport detectionReport) { |
|
|
public void onDetection(@NonNull DetectionReport detectionReport) { |
|
|
passToServiceListener(detectionReport); |
|
|
|
|
|
|
|
|
//passToServiceListener(detectionReport); |
|
|
|
|
|
wifiCommunication.sendTrue(detectionReport.toMessage()); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
/** Motion Detection**/ |
|
|
/** Motion Detection**/ |
|
|
|
|
|
|
|
|
motionDetector.setOnDetectionListener(new Detector.OnDetectionListener() { |
|
|
motionDetector.setOnDetectionListener(new Detector.OnDetectionListener() { |
|
|
@Override |
|
|
@Override |
|
|
public void onDetection(@NonNull DetectionReport detectionReport) { |
|
|
public void onDetection(@NonNull DetectionReport detectionReport) { |
|
|
passToServiceListener(detectionReport); |
|
|
|
|
|
|
|
|
//passToServiceListener(detectionReport); |
|
|
|
|
|
wifiCommunication.sendTrue(detectionReport.toMessage()); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
/** Audio Detection **/ |
|
|
/** Audio Detection **/ |
|
|
|
|
|
|
|
|
audioDetector.setOnDetectionListener(new Detector.OnDetectionListener() { |
|
|
audioDetector.setOnDetectionListener(new Detector.OnDetectionListener() { |
|
|
@Override |
|
|
@Override |
|
|
public void onDetection(@NonNull DetectionReport detectionReport) { |
|
|
public void onDetection(@NonNull DetectionReport detectionReport) { |
|
|
passToServiceListener(detectionReport); |
|
|
|
|
|
|
|
|
//passToServiceListener(detectionReport); |
|
|
|
|
|
wifiCommunication.sendTrue(detectionReport.toMessage()); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
/** Audio Recorder**/ |
|
|
/** Audio Recorder**/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Pass Detection Report to Service Detection Listener and trigger it */ |
|
|
/** Pass Detection Report to Service Detection Listener and trigger it */ |
|
|
public void passToServiceListener(DetectionReport detectionReport) { |
|
|
|
|
|
|
|
|
public void passToServiceListener(StringBuffer stringBuffer) { |
|
|
if (listener != null) { |
|
|
if (listener != null) { |
|
|
listener.onDetection(detectionReport); |
|
|
|
|
|
|
|
|
listener.onDetection(stringBuffer); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** On Detection Listener - runs when violation is reported */ |
|
|
/** On Detection Listener - runs when violation is reported */ |
|
|
public interface OnDetectionListener { |
|
|
public interface OnDetectionListener { |
|
|
void onDetection(@NonNull DetectionReport detectionReport); |
|
|
|
|
|
|
|
|
void onDetection(@NonNull StringBuffer stringBuffer); |
|
|
} |
|
|
} |
|
|
public void setOnDetectionListener(@NonNull DetectorService.OnDetectionListener listener) { |
|
|
public void setOnDetectionListener(@NonNull DetectorService.OnDetectionListener listener) { |
|
|
this.listener = listener; |
|
|
this.listener = listener; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void stringToStringbuffer(String string){ |
|
|
|
|
|
if(string != null) { |
|
|
|
|
|
stringBufferWifi.append(string).append("\n"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |