Ensures that RECORD_AUDIO permission is required to start recording.
Avoids existing crash and ensures that error message is passed up to Libjingle. Will lead to the following logcat output: E/libjingle(31404): Error(channel.cc:1514): Failed to SetSend 2 on voice channel BUG=b/21273153 R=magjed@webrtc.org Review URL: https://webrtc-codereview.appspot.com/54459004 Cr-Commit-Position: refs/heads/master@{#9236}
This commit is contained in:
parent
5779d14321
commit
9b2b40231d
@ -140,6 +140,11 @@ class WebRtcAudioRecord {
|
||||
private int InitRecording(int sampleRate, int channels) {
|
||||
Logd("InitRecording(sampleRate=" + sampleRate + ", channels=" +
|
||||
channels + ")");
|
||||
if (!WebRtcAudioUtils.hasPermission(
|
||||
context, android.Manifest.permission.RECORD_AUDIO)) {
|
||||
Loge("RECORD_AUDIO permission is missing");
|
||||
return -1;
|
||||
}
|
||||
final int bytesPerFrame = channels * (BITS_PER_SAMPLE / 8);
|
||||
final int framesPerBuffer = sampleRate / BUFFERS_PER_SECOND;
|
||||
byteBuffer = byteBuffer.allocateDirect(bytesPerFrame * framesPerBuffer);
|
||||
|
@ -10,11 +10,14 @@
|
||||
|
||||
package org.webrtc.voiceengine;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.media.audiofx.AcousticEchoCanceler;
|
||||
import android.media.audiofx.AudioEffect;
|
||||
import android.media.audiofx.AudioEffect.Descriptor;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Build;
|
||||
import android.os.Process;
|
||||
import android.util.Log;
|
||||
|
||||
import java.lang.Thread;
|
||||
@ -96,4 +99,12 @@ public final class WebRtcAudioUtils {
|
||||
+ "Model: " + Build.MODEL + ", "
|
||||
+ "Product: " + Build.PRODUCT);
|
||||
}
|
||||
|
||||
// Checks if the process has as specified permission or not.
|
||||
public static boolean hasPermission(Context context, String permission) {
|
||||
return context.checkPermission(
|
||||
permission,
|
||||
Process.myPid(),
|
||||
Process.myUid()) == PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user