Revert of Removes usage of native base::android::GetApplicationContext() (patchset #6 id:120001 of https://codereview.webrtc.org/2888093004/ )
Reason for revert:
Breaks bot on chromium.webrtc.fyi.
Original issue's description:
> Removes usage of native base::android::GetApplicationContext()
>
> BUG=webrtc:7665
>
> Review-Url: https://codereview.webrtc.org/2888093004
> Cr-Commit-Position: refs/heads/master@{#18195}
> Committed: bc83e2ee69
TBR=magjed@webrtc.org,henrika@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7665
Review-Url: https://codereview.webrtc.org/2894593002
Cr-Commit-Position: refs/heads/master@{#18196}
This commit is contained in:
@ -979,7 +979,6 @@ if (rtc_include_tests) {
|
|||||||
if (is_android) {
|
if (is_android) {
|
||||||
android_library("base_java") {
|
android_library("base_java") {
|
||||||
java_files = [
|
java_files = [
|
||||||
"java/src/org/webrtc/ContextUtils.java",
|
|
||||||
"java/src/org/webrtc/Logging.java",
|
"java/src/org/webrtc/Logging.java",
|
||||||
"java/src/org/webrtc/Size.java",
|
"java/src/org/webrtc/Size.java",
|
||||||
"java/src/org/webrtc/ThreadUtils.java",
|
"java/src/org/webrtc/ThreadUtils.java",
|
||||||
|
|||||||
@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Use of this source code is governed by a BSD-style license
|
|
||||||
* that can be found in the LICENSE file in the root of the source
|
|
||||||
* tree. An additional intellectual property rights grant can be found
|
|
||||||
* in the file PATENTS. All contributing project authors may
|
|
||||||
* be found in the AUTHORS file in the root of the source tree.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.webrtc;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class for storing the application context and retrieving it in a static context. Similar to
|
|
||||||
* org.chromium.base.ContextUtils.
|
|
||||||
*/
|
|
||||||
public class ContextUtils {
|
|
||||||
private static Context applicationContext;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stores the application context that will be returned by getApplicationContext. This is called
|
|
||||||
* by PeerConnectionFactory.initializeAndroidGlobals.
|
|
||||||
*/
|
|
||||||
public static void initialize(Context applicationContext) {
|
|
||||||
if (ContextUtils.applicationContext != null) {
|
|
||||||
throw new RuntimeException("Multiple ContextUtils.initialize calls.");
|
|
||||||
}
|
|
||||||
if (applicationContext == null) {
|
|
||||||
throw new RuntimeException("Application context cannot be null for ContextUtils.initialize.");
|
|
||||||
}
|
|
||||||
ContextUtils.applicationContext = applicationContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the stored application context.
|
|
||||||
*/
|
|
||||||
public static Context getApplicationContext() {
|
|
||||||
return applicationContext;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -83,10 +83,11 @@ AudioManager::AudioManager()
|
|||||||
j_native_registration_ = j_environment_->RegisterNatives(
|
j_native_registration_ = j_environment_->RegisterNatives(
|
||||||
"org/webrtc/voiceengine/WebRtcAudioManager", native_methods,
|
"org/webrtc/voiceengine/WebRtcAudioManager", native_methods,
|
||||||
arraysize(native_methods));
|
arraysize(native_methods));
|
||||||
j_audio_manager_.reset(
|
j_audio_manager_.reset(new JavaAudioManager(
|
||||||
new JavaAudioManager(j_native_registration_.get(),
|
j_native_registration_.get(),
|
||||||
j_native_registration_->NewObject(
|
j_native_registration_->NewObject(
|
||||||
"<init>", "(J)V", PointerTojlong(this))));
|
"<init>", "(Landroid/content/Context;J)V",
|
||||||
|
JVM::GetInstance()->context(), PointerTojlong(this))));
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioManager::~AudioManager() {
|
AudioManager::~AudioManager() {
|
||||||
|
|||||||
@ -90,10 +90,11 @@ AudioRecordJni::AudioRecordJni(AudioManager* audio_manager)
|
|||||||
j_native_registration_ = j_environment_->RegisterNatives(
|
j_native_registration_ = j_environment_->RegisterNatives(
|
||||||
"org/webrtc/voiceengine/WebRtcAudioRecord", native_methods,
|
"org/webrtc/voiceengine/WebRtcAudioRecord", native_methods,
|
||||||
arraysize(native_methods));
|
arraysize(native_methods));
|
||||||
j_audio_record_.reset(
|
j_audio_record_.reset(new JavaAudioRecord(
|
||||||
new JavaAudioRecord(j_native_registration_.get(),
|
j_native_registration_.get(),
|
||||||
j_native_registration_->NewObject(
|
j_native_registration_->NewObject(
|
||||||
"<init>", "(J)V", PointerTojlong(this))));
|
"<init>", "(Landroid/content/Context;J)V",
|
||||||
|
JVM::GetInstance()->context(), PointerTojlong(this))));
|
||||||
// Detach from this thread since we want to use the checker to verify calls
|
// Detach from this thread since we want to use the checker to verify calls
|
||||||
// from the Java based audio thread.
|
// from the Java based audio thread.
|
||||||
thread_checker_java_.DetachFromThread();
|
thread_checker_java_.DetachFromThread();
|
||||||
|
|||||||
@ -89,10 +89,11 @@ AudioTrackJni::AudioTrackJni(AudioManager* audio_manager)
|
|||||||
j_native_registration_ = j_environment_->RegisterNatives(
|
j_native_registration_ = j_environment_->RegisterNatives(
|
||||||
"org/webrtc/voiceengine/WebRtcAudioTrack", native_methods,
|
"org/webrtc/voiceengine/WebRtcAudioTrack", native_methods,
|
||||||
arraysize(native_methods));
|
arraysize(native_methods));
|
||||||
j_audio_track_.reset(
|
j_audio_track_.reset(new JavaAudioTrack(
|
||||||
new JavaAudioTrack(j_native_registration_.get(),
|
j_native_registration_.get(),
|
||||||
j_native_registration_->NewObject(
|
j_native_registration_->NewObject(
|
||||||
"<init>", "(J)V", PointerTojlong(this))));
|
"<init>", "(Landroid/content/Context;J)V",
|
||||||
|
JVM::GetInstance()->context(), PointerTojlong(this))));
|
||||||
// Detach from this thread since we want to use the checker to verify calls
|
// Detach from this thread since we want to use the checker to verify calls
|
||||||
// from the Java based audio thread.
|
// from the Java based audio thread.
|
||||||
thread_checker_java_.DetachFromThread();
|
thread_checker_java_.DetachFromThread();
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
// Note: this dependency is dangerous since it reaches into Chromium's base.
|
// Note: this dependency is dangerous since it reaches into Chromium's base.
|
||||||
// There's a risk of e.g. macro clashes. This file may only be used in tests.
|
// There's a risk of e.g. macro clashes. This file may only be used in tests.
|
||||||
RTC_PUSH_IGNORING_WUNDEF()
|
RTC_PUSH_IGNORING_WUNDEF()
|
||||||
// #include "base/android/context_utils.h"
|
#include "base/android/context_utils.h"
|
||||||
#include "base/android/jni_android.h"
|
#include "base/android/jni_android.h"
|
||||||
RTC_POP_IGNORING_WUNDEF()
|
RTC_POP_IGNORING_WUNDEF()
|
||||||
#include "webrtc/base/checks.h"
|
#include "webrtc/base/checks.h"
|
||||||
@ -35,9 +35,10 @@ void EnsureInitializedOnce() {
|
|||||||
JNIEnv* jni = ::base::android::AttachCurrentThread();
|
JNIEnv* jni = ::base::android::AttachCurrentThread();
|
||||||
JavaVM* jvm = NULL;
|
JavaVM* jvm = NULL;
|
||||||
RTC_CHECK_EQ(0, jni->GetJavaVM(&jvm));
|
RTC_CHECK_EQ(0, jni->GetJavaVM(&jvm));
|
||||||
|
jobject context = ::base::android::GetApplicationContext().obj();
|
||||||
|
|
||||||
// Initialize the Java environment (currently only used by the audio manager).
|
// Initialize the Java environment (currently only used by the audio manager).
|
||||||
webrtc::JVM::Initialize(jvm);
|
webrtc::JVM::Initialize(jvm, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnsureInitialized() {
|
void EnsureInitialized() {
|
||||||
|
|||||||
@ -20,7 +20,6 @@ import android.media.AudioTrack;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
import org.webrtc.ContextUtils;
|
|
||||||
import org.webrtc.Logging;
|
import org.webrtc.Logging;
|
||||||
|
|
||||||
// WebRtcAudioManager handles tasks that uses android.media.AudioManager.
|
// WebRtcAudioManager handles tasks that uses android.media.AudioManager.
|
||||||
@ -136,6 +135,7 @@ public class WebRtcAudioManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final long nativeAudioManager;
|
private final long nativeAudioManager;
|
||||||
|
private final Context context;
|
||||||
private final AudioManager audioManager;
|
private final AudioManager audioManager;
|
||||||
|
|
||||||
private boolean initialized = false;
|
private boolean initialized = false;
|
||||||
@ -156,11 +156,11 @@ public class WebRtcAudioManager {
|
|||||||
|
|
||||||
private final VolumeLogger volumeLogger;
|
private final VolumeLogger volumeLogger;
|
||||||
|
|
||||||
WebRtcAudioManager(long nativeAudioManager) {
|
WebRtcAudioManager(Context context, long nativeAudioManager) {
|
||||||
Logging.d(TAG, "ctor" + WebRtcAudioUtils.getThreadInfo());
|
Logging.d(TAG, "ctor" + WebRtcAudioUtils.getThreadInfo());
|
||||||
|
this.context = context;
|
||||||
this.nativeAudioManager = nativeAudioManager;
|
this.nativeAudioManager = nativeAudioManager;
|
||||||
audioManager =
|
audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||||
(AudioManager) ContextUtils.getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
WebRtcAudioUtils.logDeviceInfo(TAG);
|
WebRtcAudioUtils.logDeviceInfo(TAG);
|
||||||
}
|
}
|
||||||
@ -224,14 +224,12 @@ public class WebRtcAudioManager {
|
|||||||
|
|
||||||
// Gets the current earpiece state.
|
// Gets the current earpiece state.
|
||||||
private boolean hasEarpiece() {
|
private boolean hasEarpiece() {
|
||||||
return ContextUtils.getApplicationContext().getPackageManager().hasSystemFeature(
|
return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
|
||||||
PackageManager.FEATURE_TELEPHONY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if low-latency audio output is supported.
|
// Returns true if low-latency audio output is supported.
|
||||||
private boolean isLowLatencyOutputSupported() {
|
private boolean isLowLatencyOutputSupported() {
|
||||||
return ContextUtils.getApplicationContext().getPackageManager().hasSystemFeature(
|
return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUDIO_LOW_LATENCY);
|
||||||
PackageManager.FEATURE_AUDIO_LOW_LATENCY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if low-latency audio input is supported.
|
// Returns true if low-latency audio input is supported.
|
||||||
@ -250,8 +248,7 @@ public class WebRtcAudioManager {
|
|||||||
@TargetApi(23)
|
@TargetApi(23)
|
||||||
private boolean isProAudioSupported() {
|
private boolean isProAudioSupported() {
|
||||||
return WebRtcAudioUtils.runningOnMarshmallowOrHigher()
|
return WebRtcAudioUtils.runningOnMarshmallowOrHigher()
|
||||||
&& ContextUtils.getApplicationContext().getPackageManager().hasSystemFeature(
|
&& context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUDIO_PRO);
|
||||||
PackageManager.FEATURE_AUDIO_PRO);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the native output sample rate for this device's output stream.
|
// Returns the native output sample rate for this device's output stream.
|
||||||
|
|||||||
@ -19,7 +19,6 @@ import android.os.Process;
|
|||||||
import java.lang.System;
|
import java.lang.System;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import org.webrtc.ContextUtils;
|
|
||||||
import org.webrtc.Logging;
|
import org.webrtc.Logging;
|
||||||
import org.webrtc.ThreadUtils;
|
import org.webrtc.ThreadUtils;
|
||||||
|
|
||||||
@ -48,6 +47,7 @@ public class WebRtcAudioRecord {
|
|||||||
private static final long AUDIO_RECORD_THREAD_JOIN_TIMEOUT_MS = 2000;
|
private static final long AUDIO_RECORD_THREAD_JOIN_TIMEOUT_MS = 2000;
|
||||||
|
|
||||||
private final long nativeAudioRecord;
|
private final long nativeAudioRecord;
|
||||||
|
private final Context context;
|
||||||
|
|
||||||
private WebRtcAudioEffects effects = null;
|
private WebRtcAudioEffects effects = null;
|
||||||
|
|
||||||
@ -139,8 +139,9 @@ public class WebRtcAudioRecord {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WebRtcAudioRecord(long nativeAudioRecord) {
|
WebRtcAudioRecord(Context context, long nativeAudioRecord) {
|
||||||
Logging.d(TAG, "ctor" + WebRtcAudioUtils.getThreadInfo());
|
Logging.d(TAG, "ctor" + WebRtcAudioUtils.getThreadInfo());
|
||||||
|
this.context = context;
|
||||||
this.nativeAudioRecord = nativeAudioRecord;
|
this.nativeAudioRecord = nativeAudioRecord;
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
WebRtcAudioUtils.logDeviceInfo(TAG);
|
WebRtcAudioUtils.logDeviceInfo(TAG);
|
||||||
@ -168,8 +169,7 @@ public class WebRtcAudioRecord {
|
|||||||
|
|
||||||
private int initRecording(int sampleRate, int channels) {
|
private int initRecording(int sampleRate, int channels) {
|
||||||
Logging.d(TAG, "initRecording(sampleRate=" + sampleRate + ", channels=" + channels + ")");
|
Logging.d(TAG, "initRecording(sampleRate=" + sampleRate + ", channels=" + channels + ")");
|
||||||
if (!WebRtcAudioUtils.hasPermission(
|
if (!WebRtcAudioUtils.hasPermission(context, android.Manifest.permission.RECORD_AUDIO)) {
|
||||||
ContextUtils.getApplicationContext(), android.Manifest.permission.RECORD_AUDIO)) {
|
|
||||||
reportWebRtcAudioRecordInitError("RECORD_AUDIO permission is missing");
|
reportWebRtcAudioRecordInitError("RECORD_AUDIO permission is missing");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,7 +19,6 @@ import android.media.AudioTrack;
|
|||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import java.lang.Thread;
|
import java.lang.Thread;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import org.webrtc.ContextUtils;
|
|
||||||
import org.webrtc.Logging;
|
import org.webrtc.Logging;
|
||||||
|
|
||||||
public class WebRtcAudioTrack {
|
public class WebRtcAudioTrack {
|
||||||
@ -37,6 +36,7 @@ public class WebRtcAudioTrack {
|
|||||||
// Average number of callbacks per second.
|
// Average number of callbacks per second.
|
||||||
private static final int BUFFERS_PER_SECOND = 1000 / CALLBACK_BUFFER_SIZE_MS;
|
private static final int BUFFERS_PER_SECOND = 1000 / CALLBACK_BUFFER_SIZE_MS;
|
||||||
|
|
||||||
|
private final Context context;
|
||||||
private final long nativeAudioTrack;
|
private final long nativeAudioTrack;
|
||||||
private final AudioManager audioManager;
|
private final AudioManager audioManager;
|
||||||
|
|
||||||
@ -165,11 +165,11 @@ public class WebRtcAudioTrack {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WebRtcAudioTrack(long nativeAudioTrack) {
|
WebRtcAudioTrack(Context context, long nativeAudioTrack) {
|
||||||
Logging.d(TAG, "ctor" + WebRtcAudioUtils.getThreadInfo());
|
Logging.d(TAG, "ctor" + WebRtcAudioUtils.getThreadInfo());
|
||||||
|
this.context = context;
|
||||||
this.nativeAudioTrack = nativeAudioTrack;
|
this.nativeAudioTrack = nativeAudioTrack;
|
||||||
audioManager =
|
audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||||
(AudioManager) ContextUtils.getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
WebRtcAudioUtils.logDeviceInfo(TAG);
|
WebRtcAudioUtils.logDeviceInfo(TAG);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -118,7 +118,8 @@ class JNIEnvironment {
|
|||||||
// JNIEnv* jni = ::base::android::AttachCurrentThread();
|
// JNIEnv* jni = ::base::android::AttachCurrentThread();
|
||||||
// JavaVM* jvm = NULL;
|
// JavaVM* jvm = NULL;
|
||||||
// jni->GetJavaVM(&jvm);
|
// jni->GetJavaVM(&jvm);
|
||||||
// webrtc::JVM::Initialize(jvm);
|
// jobject context = ::base::android::GetApplicationContext();
|
||||||
|
// webrtc::JVM::Initialize(jvm, context);
|
||||||
//
|
//
|
||||||
// // Header (.h) file of example class called User.
|
// // Header (.h) file of example class called User.
|
||||||
// std::unique_ptr<JNIEnvironment> env;
|
// std::unique_ptr<JNIEnvironment> env;
|
||||||
@ -144,9 +145,9 @@ class JNIEnvironment {
|
|||||||
// JVM::Uninitialize();
|
// JVM::Uninitialize();
|
||||||
class JVM {
|
class JVM {
|
||||||
public:
|
public:
|
||||||
// Stores global handles to the Java VM interface.
|
// Stores global handles to the Java VM interface and the application context.
|
||||||
// Should be called once on a thread that is attached to the JVM.
|
// Should be called once on a thread that is attached to the JVM.
|
||||||
static void Initialize(JavaVM* jvm);
|
static void Initialize(JavaVM* jvm, jobject context);
|
||||||
// Clears handles stored in Initialize(). Must be called on same thread as
|
// Clears handles stored in Initialize(). Must be called on same thread as
|
||||||
// Initialize().
|
// Initialize().
|
||||||
static void Uninitialize();
|
static void Uninitialize();
|
||||||
@ -167,9 +168,10 @@ class JVM {
|
|||||||
|
|
||||||
// TODO(henrika): can we make these private?
|
// TODO(henrika): can we make these private?
|
||||||
JavaVM* jvm() const { return jvm_; }
|
JavaVM* jvm() const { return jvm_; }
|
||||||
|
jobject context() const { return context_; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
JVM(JavaVM* jvm);
|
JVM(JavaVM* jvm, jobject context);
|
||||||
~JVM();
|
~JVM();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -177,6 +179,7 @@ class JVM {
|
|||||||
|
|
||||||
rtc::ThreadChecker thread_checker_;
|
rtc::ThreadChecker thread_checker_;
|
||||||
JavaVM* const jvm_;
|
JavaVM* const jvm_;
|
||||||
|
jobject context_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|||||||
@ -217,10 +217,10 @@ std::string JNIEnvironment::JavaToStdString(const jstring& j_string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void JVM::Initialize(JavaVM* jvm) {
|
void JVM::Initialize(JavaVM* jvm, jobject context) {
|
||||||
ALOGD("JVM::Initialize%s", GetThreadInfo().c_str());
|
ALOGD("JVM::Initialize%s", GetThreadInfo().c_str());
|
||||||
RTC_CHECK(!g_jvm);
|
RTC_CHECK(!g_jvm);
|
||||||
g_jvm = new JVM(jvm);
|
g_jvm = new JVM(jvm, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
@ -237,9 +237,11 @@ JVM* JVM::GetInstance() {
|
|||||||
return g_jvm;
|
return g_jvm;
|
||||||
}
|
}
|
||||||
|
|
||||||
JVM::JVM(JavaVM* jvm) : jvm_(jvm) {
|
JVM::JVM(JavaVM* jvm, jobject context)
|
||||||
|
: jvm_(jvm) {
|
||||||
ALOGD("JVM::JVM%s", GetThreadInfo().c_str());
|
ALOGD("JVM::JVM%s", GetThreadInfo().c_str());
|
||||||
RTC_CHECK(jni()) << "AttachCurrentThread() must be called on this thread.";
|
RTC_CHECK(jni()) << "AttachCurrentThread() must be called on this thread.";
|
||||||
|
context_ = NewGlobalRef(jni(), context);
|
||||||
LoadClasses(jni());
|
LoadClasses(jni());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,6 +249,7 @@ JVM::~JVM() {
|
|||||||
ALOGD("JVM::~JVM%s", GetThreadInfo().c_str());
|
ALOGD("JVM::~JVM%s", GetThreadInfo().c_str());
|
||||||
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
||||||
FreeClassReferences(jni());
|
FreeClassReferences(jni());
|
||||||
|
DeleteGlobalRef(jni(), context_);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<JNIEnvironment> JVM::environment() {
|
std::unique_ptr<JNIEnvironment> JVM::environment() {
|
||||||
|
|||||||
@ -19,6 +19,7 @@
|
|||||||
// Since we use Chromes build system for creating the gtest binary, this should
|
// Since we use Chromes build system for creating the gtest binary, this should
|
||||||
// be fine.
|
// be fine.
|
||||||
RTC_PUSH_IGNORING_WUNDEF()
|
RTC_PUSH_IGNORING_WUNDEF()
|
||||||
|
#include "base/android/context_utils.h"
|
||||||
#include "base/android/jni_android.h"
|
#include "base/android/jni_android.h"
|
||||||
RTC_POP_IGNORING_WUNDEF()
|
RTC_POP_IGNORING_WUNDEF()
|
||||||
|
|
||||||
@ -40,10 +41,11 @@ void EnsureInitializedOnce() {
|
|||||||
JNIEnv* jni = ::base::android::AttachCurrentThread();
|
JNIEnv* jni = ::base::android::AttachCurrentThread();
|
||||||
JavaVM* jvm = NULL;
|
JavaVM* jvm = NULL;
|
||||||
RTC_CHECK_EQ(0, jni->GetJavaVM(&jvm));
|
RTC_CHECK_EQ(0, jni->GetJavaVM(&jvm));
|
||||||
|
jobject context = ::base::android::GetApplicationContext().obj();
|
||||||
|
|
||||||
RTC_CHECK(rtc::InitializeSSL()) << "Failed to InitializeSSL()";
|
RTC_CHECK(rtc::InitializeSSL()) << "Failed to InitializeSSL()";
|
||||||
|
|
||||||
webrtc::JVM::Initialize(jvm);
|
webrtc::JVM::Initialize(jvm, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|||||||
@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
package org.webrtc;
|
package org.webrtc;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,7 +30,6 @@ public class PeerConnectionFactory {
|
|||||||
|
|
||||||
private static final String TAG = "PeerConnectionFactory";
|
private static final String TAG = "PeerConnectionFactory";
|
||||||
private final long nativeFactory;
|
private final long nativeFactory;
|
||||||
private static Context applicationContext;
|
|
||||||
private static Thread networkThread;
|
private static Thread networkThread;
|
||||||
private static Thread workerThread;
|
private static Thread workerThread;
|
||||||
private static Thread signalingThread;
|
private static Thread signalingThread;
|
||||||
@ -54,19 +52,14 @@ public class PeerConnectionFactory {
|
|||||||
|
|
||||||
// Must be called at least once before creating a PeerConnectionFactory
|
// Must be called at least once before creating a PeerConnectionFactory
|
||||||
// (for example, at application startup time).
|
// (for example, at application startup time).
|
||||||
public static native void nativeInitializeAndroidGlobals(
|
public static native void initializeAndroidGlobals(
|
||||||
Context context, boolean videoHwAcceleration);
|
android.content.Context context, boolean videoHwAcceleration);
|
||||||
|
|
||||||
public static void initializeAndroidGlobals(Context context, boolean videoHwAcceleration) {
|
|
||||||
ContextUtils.initialize(context);
|
|
||||||
nativeInitializeAndroidGlobals(context, videoHwAcceleration);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Older signature of initializeAndroidGlobals. The extra parameters are now meaningless.
|
// Older signature of initializeAndroidGlobals. The extra parameters are now meaningless.
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static boolean initializeAndroidGlobals(Object context, boolean initializeAudio,
|
public static boolean initializeAndroidGlobals(Object context, boolean initializeAudio,
|
||||||
boolean initializeVideo, boolean videoHwAcceleration) {
|
boolean initializeVideo, boolean videoHwAcceleration) {
|
||||||
initializeAndroidGlobals((Context) context, videoHwAcceleration);
|
initializeAndroidGlobals((android.content.Context) context, videoHwAcceleration);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1136,7 +1136,7 @@ JOW(jlong, PeerConnectionFactory_nativeCreateObserver)(
|
|||||||
return (jlong)new PCOJava(jni, j_observer);
|
return (jlong)new PCOJava(jni, j_observer);
|
||||||
}
|
}
|
||||||
|
|
||||||
JOW(void, PeerConnectionFactory_nativeInitializeAndroidGlobals)
|
JOW(void, PeerConnectionFactory_initializeAndroidGlobals)
|
||||||
(JNIEnv* jni,
|
(JNIEnv* jni,
|
||||||
jclass,
|
jclass,
|
||||||
jobject context,
|
jobject context,
|
||||||
@ -1146,7 +1146,7 @@ JOW(void, PeerConnectionFactory_nativeInitializeAndroidGlobals)
|
|||||||
if (!factory_static_initialized) {
|
if (!factory_static_initialized) {
|
||||||
RTC_DCHECK(j_application_context == nullptr);
|
RTC_DCHECK(j_application_context == nullptr);
|
||||||
j_application_context = NewGlobalRef(jni, context);
|
j_application_context = NewGlobalRef(jni, context);
|
||||||
webrtc::JVM::Initialize(GetJVM());
|
webrtc::JVM::Initialize(GetJVM(), context);
|
||||||
factory_static_initialized = true;
|
factory_static_initialized = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -532,17 +532,3 @@ rtc_source_set("audio_codec_mocks") {
|
|||||||
"//testing/gmock",
|
"//testing/gmock",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_android) {
|
|
||||||
android_library("native_test_java") {
|
|
||||||
testonly = true
|
|
||||||
java_files = [
|
|
||||||
"android/org/webrtc/native_test/RTCNativeUnitTest.java",
|
|
||||||
"android/org/webrtc/native_test/RTCNativeUnitTestActivity.java",
|
|
||||||
]
|
|
||||||
deps = [
|
|
||||||
"//testing/android/native_test:native_test_java",
|
|
||||||
"//webrtc/base:base_java",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,46 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
Copyright 2017 The WebRTC project authors. All Rights Reserved.
|
|
||||||
|
|
||||||
Use of this source code is governed by a BSD-style license
|
|
||||||
that can be found in the LICENSE file in the root of the source
|
|
||||||
tree. An additional intellectual property rights grant can be found
|
|
||||||
in the file PATENTS. All contributing project authors may
|
|
||||||
be found in the AUTHORS file in the root of the source tree.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
package="org.webrtc.native_test"
|
|
||||||
android:versionCode="1"
|
|
||||||
android:versionName="1.0">
|
|
||||||
|
|
||||||
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23" />
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
|
||||||
<uses-permission android:name="android.permission.BLUETOOTH"/>
|
|
||||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
|
|
||||||
<uses-permission android:name="android.permission.CAMERA" />
|
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
|
||||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
|
|
||||||
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
|
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
|
||||||
|
|
||||||
<application android:label="NativeTests"
|
|
||||||
android:name="org.chromium.base.BaseChromiumApplication">
|
|
||||||
<uses-library android:name="android.test.runner"/>
|
|
||||||
<activity android:name=".RTCNativeUnitTestActivity"
|
|
||||||
android:label="NativeTest"
|
|
||||||
android:configChanges="orientation|keyboardHidden"
|
|
||||||
android:process=":test_process">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.MAIN" />
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
</application>
|
|
||||||
|
|
||||||
<instrumentation android:name="org.chromium.native_test.NativeTestInstrumentationTestRunner"
|
|
||||||
android:targetPackage="org.webrtc.native_test"
|
|
||||||
android:label="Instrumentation entry point for org.webrtc.native_test"/>
|
|
||||||
|
|
||||||
</manifest>
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Use of this source code is governed by a BSD-style license
|
|
||||||
* that can be found in the LICENSE file in the root of the source
|
|
||||||
* tree. An additional intellectual property rights grant can be found
|
|
||||||
* in the file PATENTS. All contributing project authors may
|
|
||||||
* be found in the AUTHORS file in the root of the source tree.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.webrtc.native_test;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import org.chromium.native_test.NativeUnitTest;
|
|
||||||
import org.webrtc.ContextUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Native unit test that calls ContextUtils.initialize for WebRTC.
|
|
||||||
*/
|
|
||||||
public class RTCNativeUnitTest extends NativeUnitTest {
|
|
||||||
@Override
|
|
||||||
public void preCreate(Activity activity) {
|
|
||||||
super.preCreate(activity);
|
|
||||||
ContextUtils.initialize(activity.getApplicationContext());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Use of this source code is governed by a BSD-style license
|
|
||||||
* that can be found in the LICENSE file in the root of the source
|
|
||||||
* tree. An additional intellectual property rights grant can be found
|
|
||||||
* in the file PATENTS. All contributing project authors may
|
|
||||||
* be found in the AUTHORS file in the root of the source tree.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.webrtc.native_test;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Activity that uses RTCNativeUnitTest to run the tests.
|
|
||||||
*/
|
|
||||||
public class RTCNativeUnitTestActivity extends Activity {
|
|
||||||
private RTCNativeUnitTest mTest = new RTCNativeUnitTest();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
mTest.preCreate(this);
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
mTest.postCreate(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStart() {
|
|
||||||
super.onStart();
|
|
||||||
mTest.postStart(this, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -266,10 +266,6 @@ template("rtc_test") {
|
|||||||
if (defined(invoker.public_configs)) {
|
if (defined(invoker.public_configs)) {
|
||||||
public_configs += invoker.public_configs
|
public_configs += invoker.public_configs
|
||||||
}
|
}
|
||||||
if (is_android) {
|
|
||||||
android_manifest = "//webrtc/test/android/AndroidManifest.xml"
|
|
||||||
deps += [ "//webrtc/test:native_test_java" ]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user