Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f81b4288 authored by Kryten2k35's avatar Kryten2k35 Committed by Gerrit Code Review
Browse files

Call recording encoder/format choice 1/3

Forward port of 16a17cd0

Change-Id: I95620bf944e18491652c716890396c3da4be70c4
parent f831b882
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -17,4 +17,5 @@
<resources>
    <bool name="call_recording_enabled">false</bool>
    <integer name="call_recording_audio_source">1</integer>
    <integer name="call_recording_audio_encoder">0</integer>
</resources>
+34 −3
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.os.IBinder;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.text.TextUtils;
import android.provider.Settings;
import android.util.Log;

import com.android.services.callrecorder.common.CallRecording;
@@ -53,6 +54,8 @@ public class CallRecorderService extends Service {

    private SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyMMdd_HHmmssSSS");

    private int mDefaultEncoder;

    private final ICallRecorderService.Stub mBinder = new ICallRecorderService.Stub() {
        @Override
        public CallRecording stopRecording() {
@@ -87,6 +90,7 @@ public class CallRecorderService extends Service {
    @Override
    public void onCreate() {
        if (DBG) Log.d(TAG, "Creating CallRecorderService");
        mDefaultEncoder = getResources().getInteger(R.integer.call_recording_audio_encoder);
    }

    @Override
@@ -99,6 +103,26 @@ public class CallRecorderService extends Service {
        return SystemProperties.getInt(AUDIO_SOURCE_PROPERTY, defaultValue);
    }

    private int getAudioFormat() {
        int formatValue =  Settings.System.getInt(
                getContentResolver(), Settings.System.CALL_RECORDING_FORMAT, mDefaultEncoder);
        if (formatValue == 0){
            return MediaRecorder.OutputFormat.AMR_WB;
        } else {
            return MediaRecorder.OutputFormat.MPEG_4;
        }
    }

    private int getAudioEncoder() {
        int formatValue =  Settings.System.getInt(
                getContentResolver(), Settings.System.CALL_RECORDING_FORMAT, mDefaultEncoder);
        if (formatValue == 0){
            return MediaRecorder.AudioEncoder.AMR_WB;
        } else {
            return MediaRecorder.AudioEncoder.HE_AAC;
        }
    }

    private synchronized boolean startRecordingInternal(File file) {
        if (mMediaRecorder != null) {
            if (DBG) {
@@ -114,8 +138,8 @@ public class CallRecorderService extends Service {
            int audioSource = getAudioSource();
            if (DBG) Log.d(TAG, "Creating media recorder with audio source " + audioSource);
            mMediaRecorder.setAudioSource(audioSource);
            mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
            mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
            mMediaRecorder.setOutputFormat(getAudioFormat());
            mMediaRecorder.setAudioEncoder(getAudioEncoder());
        } catch (IllegalStateException e) {
            Log.w(TAG, "Error initializing media recorder", e);
            return false;
@@ -180,10 +204,17 @@ public class CallRecorderService extends Service {

    private String generateFilename(String number) {
        String timestamp = DATE_FORMAT.format(new Date());

        if (TextUtils.isEmpty(number)) {
            number = "unknown";
        }

        int audioFormat = getAudioFormat();
        if (audioFormat == MediaRecorder.OutputFormat.AMR_WB) {
            return number + "_" + timestamp + ".amr";
        } else {
            return number + "_" + timestamp + ".m4a ";
        }
    }

    public static boolean isEnabled(Context context) {