new libs and expceptions
This commit is contained in:
parent
f2dc6e97dc
commit
1c95d7db12
4 changed files with 29 additions and 67 deletions
|
|
@ -54,6 +54,7 @@ import com.github.axet.audiorecorder.services.RecordingService;
|
|||
import org.json.JSONException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class MainActivity extends AppCompatThemeActivity {
|
||||
public final static String TAG = MainActivity.class.getSimpleName();
|
||||
|
|
@ -636,7 +637,7 @@ public class MainActivity extends AppCompatThemeActivity {
|
|||
if (Storage.permitted(MainActivity.this, permissions)) {
|
||||
try {
|
||||
storage.migrateLocalStorage();
|
||||
} catch (RuntimeException e) {
|
||||
} catch (RuntimeException | IOException e) {
|
||||
ErrorDialog.Error(MainActivity.this, e);
|
||||
}
|
||||
recordings.load(false, null);
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@ import android.content.Intent;
|
|||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Rect;
|
||||
import android.media.AudioFormat;
|
||||
import android.media.MediaRecorder;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
|
@ -22,7 +20,6 @@ import android.provider.MediaStore;
|
|||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.view.WindowCallbackWrapper;
|
||||
import android.telephony.PhoneStateListener;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
|
|
@ -38,6 +35,7 @@ import android.widget.TextView;
|
|||
|
||||
import com.github.axet.androidlibrary.activities.AppCompatThemeActivity;
|
||||
import com.github.axet.androidlibrary.animations.MarginBottomAnimation;
|
||||
import com.github.axet.androidlibrary.app.PhoneStateChangeListener;
|
||||
import com.github.axet.androidlibrary.services.FileProvider;
|
||||
import com.github.axet.androidlibrary.services.StorageProvider;
|
||||
import com.github.axet.androidlibrary.sound.AudioTrack;
|
||||
|
|
@ -61,12 +59,7 @@ import com.github.axet.audiorecorder.services.EncodingService;
|
|||
import com.github.axet.audiorecorder.services.RecordingService;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.nio.ShortBuffer;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.io.IOException;
|
||||
|
||||
public class RecordingActivity extends AppCompatThemeActivity {
|
||||
public static final String TAG = RecordingActivity.class.getSimpleName();
|
||||
|
|
@ -86,7 +79,7 @@ public class RecordingActivity extends AppCompatThemeActivity {
|
|||
public static final String START_RECORDING = RecordingService.class.getCanonicalName() + ".START_RECORDING";
|
||||
public static final String STOP_RECORDING = RecordingService.class.getCanonicalName() + ".STOP_RECORDING";
|
||||
|
||||
PhoneStateChangeListener pscl = new PhoneStateChangeListener();
|
||||
PhoneStateChangeListener pscl;
|
||||
Headset headset;
|
||||
Intent recordSoundIntent = null;
|
||||
|
||||
|
|
@ -300,65 +293,29 @@ public class RecordingActivity extends AppCompatThemeActivity {
|
|||
}
|
||||
}
|
||||
|
||||
class PhoneStateChangeListener extends PhoneStateListener {
|
||||
public boolean wasRinging;
|
||||
class PhoneStateChangeListener extends com.github.axet.androidlibrary.app.PhoneStateChangeListener {
|
||||
public boolean pausedByCall;
|
||||
@TargetApi(31)
|
||||
TelephonyCallback e;
|
||||
|
||||
@TargetApi(31)
|
||||
public class TelephonyCallback extends android.telephony.TelephonyCallback implements android.telephony.TelephonyCallback.CallStateListener {
|
||||
@Override
|
||||
public void onCallStateChanged(int i) {
|
||||
PhoneStateChangeListener.this.onCallStateChanged(i, "");
|
||||
}
|
||||
public PhoneStateChangeListener(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public void create() {
|
||||
Context context = RecordingActivity.this;
|
||||
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
if (Build.VERSION.SDK_INT >= 31 && getApplicationInfo().targetSdkVersion >= 31) {
|
||||
if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
|
||||
e = new TelephonyCallback();
|
||||
tm.registerTelephonyCallback(getMainExecutor(), e);
|
||||
}
|
||||
} else {
|
||||
tm.listen(this, PhoneStateListener.LISTEN_CALL_STATE);
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
Context context = RecordingActivity.this;
|
||||
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
if (Build.VERSION.SDK_INT >= 31 && getApplicationInfo().targetSdkVersion >= 31) {
|
||||
if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED)
|
||||
tm.unregisterTelephonyCallback(e);
|
||||
} else {
|
||||
tm.listen(this, PhoneStateListener.LISTEN_NONE);
|
||||
@Override
|
||||
public void onAnswered() {
|
||||
super.onAnswered();
|
||||
if (recording.thread != null) {
|
||||
stopRecording(getString(R.string.hold_by_call), false);
|
||||
pausedByCall = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCallStateChanged(int s, String incomingNumber) {
|
||||
switch (s) {
|
||||
case TelephonyManager.CALL_STATE_RINGING:
|
||||
wasRinging = true;
|
||||
break;
|
||||
case TelephonyManager.CALL_STATE_OFFHOOK:
|
||||
wasRinging = true;
|
||||
if (recording.thread != null) {
|
||||
stopRecording(getString(R.string.hold_by_call), false);
|
||||
pausedByCall = true;
|
||||
}
|
||||
break;
|
||||
case TelephonyManager.CALL_STATE_IDLE:
|
||||
if (pausedByCall) {
|
||||
if (receiver.isRecordingReady())
|
||||
; // startRecording();
|
||||
}
|
||||
wasRinging = false;
|
||||
pausedByCall = false;
|
||||
break;
|
||||
public void onIdle() {
|
||||
super.onIdle();
|
||||
if (pausedByCall) {
|
||||
// if (receiver.isRecordingReady())
|
||||
// startRecording();
|
||||
pausedByCall = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -439,6 +396,7 @@ public class RecordingActivity extends AppCompatThemeActivity {
|
|||
receiver.filter.addAction(ACTION_FINISH_RECORDING);
|
||||
receiver.registerReceiver(this);
|
||||
|
||||
pscl = new PhoneStateChangeListener(this);
|
||||
final SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
if (shared.getBoolean(AudioApplication.PREFERENCE_CALL, false))
|
||||
pscl.create();
|
||||
|
|
@ -458,10 +416,10 @@ public class RecordingActivity extends AppCompatThemeActivity {
|
|||
recording.e.close();
|
||||
recording.e = null;
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
Storage.delete(RecordingActivity.this, recording.targetUri);
|
||||
} catch (RuntimeException | IOException e) {
|
||||
Error(e);
|
||||
}
|
||||
Storage.delete(RecordingActivity.this, recording.targetUri);
|
||||
}
|
||||
Storage.delete(recording.storage.getTempRecording());
|
||||
finish();
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import org.json.JSONObject;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -201,14 +202,14 @@ public class EncodingStorage extends HashMap<File, EncodingStorage.Info> {
|
|||
}, new Runnable() {
|
||||
@Override
|
||||
public void run() { // or error
|
||||
Storage.delete(storage.getContext(), fly.targetUri); // fly has fd, delete target manually
|
||||
try {
|
||||
Storage.delete(storage.getContext(), fly.targetUri); // fly has fd, delete target manually
|
||||
Intent intent = new Intent()
|
||||
.putExtra("in", encoder.in)
|
||||
.putExtra("info", info.save().toString())
|
||||
.putExtra("e", encoder.getException());
|
||||
Post(ERROR, intent);
|
||||
} catch (JSONException e) {
|
||||
} catch (JSONException | IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import android.preference.PreferenceManager;
|
|||
import com.github.axet.androidlibrary.services.StorageProvider;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
|
@ -135,7 +137,7 @@ public class Storage extends com.github.axet.audiolibrary.app.Storage {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void migrateLocalStorage() {
|
||||
public void migrateLocalStorage() throws IOException {
|
||||
super.migrateLocalStorage();
|
||||
deleteTmp();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue