Skip to content

Commit

Permalink
Add an advanced log for calling listen() without permission euphony…
Browse files Browse the repository at this point in the history
…-io#205 (euphony-io#217)

* Add advanced logs to call listen() without permission use try-catch statements (euphony-io#205)
* Made `EuRxManagerTest.java`
* Apply indent to `EuRxManager.java`
* Resolved euphony-io#217 

Co-authored-by: zion830 <[email protected]>
  • Loading branch information
sunyeongan and zion830 authored Sep 6, 2022
1 parent ca9985b commit cb22a26
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
15 changes: 15 additions & 0 deletions euphony/src/androidTest/java/co/euphony/rx/EuRxManagerTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import androidx.test.ext.junit.runners.AndroidJUnit4
import co.euphony.rx.EuRxManager
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class EuRxManagerTest {

@Test(expected = Test.None::class) /* no exception expected */
fun withExceptionHandlingNoErrorOccurs() {
val rxManager = EuRxManager()
rxManager.listen()
}

}
15 changes: 11 additions & 4 deletions euphony/src/main/java/co/euphony/rx/AudioRecorder.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package co.euphony.rx;

import java.nio.ByteBuffer;

import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;
import android.util.Log;

import java.nio.ByteBuffer;

public class AudioRecorder {

private AudioRecord audioRecord;
private boolean running;
private boolean swtWindowing; //TEST WINDOWING
private final String LOG = "AudioRecoder";

/**
* Constructor.
Expand Down Expand Up @@ -56,8 +58,13 @@ public int read(ByteBuffer buffer, int bufferSize, short windowNum) {
*/
public void start() {
if (!running) {
audioRecord.startRecording();
running = true;
try {
audioRecord.startRecording();
running = true;
} catch (IllegalStateException e) {
running = false;
Log.e(LOG, "Before calling listen(), you should acquire RECORD_AUDIO permission.");
}
}
}

Expand Down
27 changes: 13 additions & 14 deletions euphony/src/main/java/co/euphony/rx/EuRxManager.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package co.euphony.rx;


import static co.euphony.rx.EuPI.EuPIStatus.KEY_DOWN;
import static co.euphony.rx.EuPI.EuPIStatus.KEY_PRESSED;
import static co.euphony.rx.EuPI.EuPIStatus.KEY_UP;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;

import java.util.ArrayList;

import co.euphony.common.Constants;
import co.euphony.common.EuNativeConnector;
import co.euphony.util.EuOption;

import static co.euphony.rx.EuPI.EuPIStatus.KEY_DOWN;
import static co.euphony.rx.EuPI.EuPIStatus.KEY_PRESSED;
import static co.euphony.rx.EuPI.EuPIStatus.KEY_UP;

public class EuRxManager {

private final String LOG = "EuRxManager";
Expand Down Expand Up @@ -102,8 +102,7 @@ public boolean listen() {
return listenOnNative();
}

public void finish()
{
public void finish() {
if(rxEngineType == RxEngineType.EUPHONY_JAVA_ENGINE) {
if (mListenThread != null) {
mListenThread.interrupt();
Expand Down Expand Up @@ -156,17 +155,17 @@ public RxManagerStatus getStatus() {
}

private AcousticSensor mAcousticSensor;

public AcousticSensor getAcousticSensor() {
return mAcousticSensor;
}

public void setAcousticSensor(AcousticSensor iAcousticSensor) {
this.mAcousticSensor = iAcousticSensor;
}

private final Handler mHandler = new Handler(Looper.getMainLooper()){
public void handleMessage(Message msg){
public void handleMessage(Message msg){
switch(msg.what){
case RX_MODE:
mAcousticSensor.notify(msg.obj + "");
Expand All @@ -176,8 +175,8 @@ public void handleMessage(Message msg){
eupi.getCallback().call();
break;

default:
break;
default:
break;
}
}
};
Expand All @@ -200,7 +199,7 @@ public void setRxEngineType(RxEngineType type) {

private class RxRunner extends EuFreqObject implements Runnable{
@Override
public void run()
public void run()
{
while (!Thread.currentThread().isInterrupted()) {
processFFT();
Expand All @@ -214,7 +213,7 @@ public void run()
msg.what = RX_MODE;
msg.obj = null;
if(mOption.getCodingType() == EuOption.CodingType.BASE16) {
msg.obj = EuDataDecoder.decodeStaticHexCharSource(getReceivedData());
msg.obj = EuDataDecoder.decodeStaticHexCharSource(getReceivedData());
}
this.setCompleted(false);
mHandler.sendMessage(msg);
Expand Down

0 comments on commit cb22a26

Please sign in to comment.