diff options
author | lambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-29 17:56:56 +0000 |
---|---|---|
committer | lambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-29 17:56:56 +0000 |
commit | 6856e2d374b954e0232078d4e30e3d6f38f63567 (patch) | |
tree | 4fa8b7f91c8dfbd941a3496aa19e98d1e272aae6 /remoting | |
parent | 03f2c5e870a7e6ae30af86445ac5d421da4d434a (diff) | |
download | chromium_src-6856e2d374b954e0232078d4e30e3d6f38f63567.zip chromium_src-6856e2d374b954e0232078d4e30e3d6f38f63567.tar.gz chromium_src-6856e2d374b954e0232078d4e30e3d6f38f63567.tar.bz2 |
Use jni_generator in Chromoting Android client
This removes all manually-written JNI interface code and uses the
automatically generated JNI stubs instead.
BUG=304225
R=digit@chromium.org, solb@chromium.org
Review URL: https://codereview.chromium.org/29583003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231600 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/android/java/src/org/chromium/chromoting/Chromoting.java | 6 | ||||
-rw-r--r-- | remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java | 57 | ||||
-rw-r--r-- | remoting/client/jni/DEPS | 1 | ||||
-rw-r--r-- | remoting/client/jni/chromoting_jni_onload.cc | 32 | ||||
-rw-r--r-- | remoting/client/jni/chromoting_jni_runtime.cc | 186 | ||||
-rw-r--r-- | remoting/client/jni/chromoting_jni_runtime.h | 5 | ||||
-rw-r--r-- | remoting/client/jni/jni_interface.cc | 151 | ||||
-rw-r--r-- | remoting/remoting.gyp | 17 |
8 files changed, 205 insertions, 250 deletions
diff --git a/remoting/android/java/src/org/chromium/chromoting/Chromoting.java b/remoting/android/java/src/org/chromium/chromoting/Chromoting.java index 07d896f..22cc376 100644 --- a/remoting/android/java/src/org/chromium/chromoting/Chromoting.java +++ b/remoting/android/java/src/org/chromium/chromoting/Chromoting.java @@ -230,9 +230,9 @@ public class Chromoting extends Activity { // Send our HTTP request to the directory server. URLConnection link = - new URL(HOST_LIST_PATH + JniInterface.getApiKey()).openConnection(); - link.addRequestProperty("client_id", JniInterface.getClientId()); - link.addRequestProperty("client_secret", JniInterface.getClientSecret()); + new URL(HOST_LIST_PATH + JniInterface.nativeGetApiKey()).openConnection(); + link.addRequestProperty("client_id", JniInterface.nativeGetClientId()); + link.addRequestProperty("client_secret", JniInterface.nativeGetClientSecret()); link.setRequestProperty("Authorization", "OAuth " + authToken); // Listen for the server to respond. diff --git a/remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java b/remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java index fb9110d..d8ca6a7 100644 --- a/remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java +++ b/remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java @@ -22,6 +22,8 @@ import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; +import org.chromium.base.CalledByNative; +import org.chromium.base.JNINamespace; import org.chromium.chromoting.R; import java.nio.ByteBuffer; @@ -31,6 +33,7 @@ import java.nio.ByteOrder; * Initializes the Chromium remoting library, and provides JNI calls into it. * All interaction with the native code is centralized in this class. */ +@JNINamespace("remoting") public class JniInterface { /** The status code indicating successful connection. */ private static final int SUCCESSFUL_CONNECTION = 3; @@ -57,19 +60,20 @@ public class JniInterface { } System.loadLibrary("remoting_client_jni"); - loadNative(context); + + nativeLoadNative(context); sLoaded = true; } /** Performs the native portion of the initialization. */ - private static native void loadNative(Context context); + private static native void nativeLoadNative(Context context); /* * API/OAuth2 keys access. */ - public static native String getApiKey(); - public static native String getClientId(); - public static native String getClientSecret(); + public static native String nativeGetApiKey(); + public static native String nativeGetClientId(); + public static native String nativeGetClientSecret(); /* * Connection-initiating state machine. @@ -96,7 +100,7 @@ public class JniInterface { sSuccessCallback = successCallback; SharedPreferences prefs = sContext.getPreferences(Activity.MODE_PRIVATE); - connectNative(username, authToken, hostJid, hostId, hostPubkey, + nativeConnect(username, authToken, hostJid, hostId, hostPubkey, prefs.getString(hostId + "_id", ""), prefs.getString(hostId + "_secret", "")); sConnected = true; } @@ -112,7 +116,7 @@ public class JniInterface { } } - disconnectNative(); + nativeDisconnect(); sSuccessCallback = null; sConnected = false; @@ -123,11 +127,11 @@ public class JniInterface { } /** Performs the native portion of the connection. */ - private static native void connectNative(String username, String authToken, String hostJid, + private static native void nativeConnect(String username, String authToken, String hostJid, String hostId, String hostPubkey, String pairId, String pairSecret); /** Performs the native portion of the cleanup. */ - private static native void disconnectNative(); + private static native void nativeDisconnect(); /** Position of cursor hotspot within cursor image. */ public static Point getCursorHotspot() { return sCursorHotspot; } @@ -154,6 +158,7 @@ public class JniInterface { private static Bitmap sCursorBitmap = null; /** Reports whenever the connection status changes. */ + @CalledByNative private static void reportConnectionStatus(int state, int error) { if (state < SUCCESSFUL_CONNECTION && error == 0) { // The connection is still being established, so we'll report the current progress. @@ -201,6 +206,7 @@ public class JniInterface { } /** Prompts the user to enter a PIN. */ + @CalledByNative private static void displayAuthenticationPrompt(boolean pairingSupported) { AlertDialog.Builder pinPrompt = new AlertDialog.Builder(sContext); pinPrompt.setTitle(sContext.getString(R.string.pin_entry_title)); @@ -223,8 +229,8 @@ public class JniInterface { @Override public void onClick(DialogInterface dialog, int which) { Log.i("jniiface", "User provided a PIN code"); - authenticationResponse(String.valueOf(pinTextView.getText()), - pinCheckBox.isChecked()); + nativeAuthenticationResponse(String.valueOf(pinTextView.getText()), + pinCheckBox.isChecked()); } }); @@ -266,6 +272,7 @@ public class JniInterface { } /** Saves newly-received pairing credentials to permanent storage. */ + @CalledByNative private static void commitPairingCredentials(String host, byte[] id, byte[] secret) { synchronized (sContext) { sContext.getPreferences(Activity.MODE_PRIVATE).edit(). @@ -289,14 +296,16 @@ public class JniInterface { if (!sConnected || sRedrawCallback == null) return false; } - scheduleRedrawNative(); + nativeScheduleRedraw(); return true; } /** Performs the redrawing callback. This is a no-op if the window isn't visible. */ + @CalledByNative private static void redrawGraphicsInternal() { - if (sRedrawCallback != null) + if (sRedrawCallback != null) { sRedrawCallback.run(); + } } /** @@ -318,9 +327,9 @@ public class JniInterface { } /** - * Sets a new video frame. Called from native code on the native graphics thread when a new - * frame is allocated. + * Sets a new video frame. Called on the native graphics thread when a new frame is allocated. */ + @CalledByNative private static void setVideoFrame(Bitmap bitmap) { if (Looper.myLooper() == Looper.getMainLooper()) { Log.w("jniiface", "Video frame updated on UI thread"); @@ -335,14 +344,16 @@ public class JniInterface { * Creates a new Bitmap to hold video frame pixels. Called by native code which stores a global * reference to the Bitmap and writes the decoded frame pixels to it. */ + @CalledByNative private static Bitmap newBitmap(int width, int height) { return Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); } /** - * Updates the cursor shape. This is called from native code on the graphics thread when - * receiving a new cursor shape from the host. + * Updates the cursor shape. This is called on the graphics thread when receiving a new cursor + * shape from the host. */ + @CalledByNative public static void updateCursorShape(int width, int height, int hotspotX, int hotspotY, ByteBuffer buffer) { sCursorHotspot = new Point(hotspotX, hotspotY); @@ -359,7 +370,7 @@ public class JniInterface { return; } - mouseActionNative(x, y, whichButton, buttonDown); + nativeMouseAction(x, y, whichButton, buttonDown); } /** Presses and releases the specified (nonnegative) key. */ @@ -368,18 +379,18 @@ public class JniInterface { return; } - keyboardActionNative(keyCode, keyDown); + nativeKeyboardAction(keyCode, keyDown); } /** Performs the native response to the user's PIN. */ - private static native void authenticationResponse(String pin, boolean createPair); + private static native void nativeAuthenticationResponse(String pin, boolean createPair); /** Schedules a redraw on the native graphics thread. */ - private static native void scheduleRedrawNative(); + private static native void nativeScheduleRedraw(); /** Passes mouse information to the native handling code. */ - private static native void mouseActionNative(int x, int y, int whichButton, boolean buttonDown); + private static native void nativeMouseAction(int x, int y, int whichButton, boolean buttonDown); /** Passes key press information to the native handling code. */ - private static native void keyboardActionNative(int keyCode, boolean keyDown); + private static native void nativeKeyboardAction(int keyCode, boolean keyDown); } diff --git a/remoting/client/jni/DEPS b/remoting/client/jni/DEPS index 26dcd15..85fd773 100644 --- a/remoting/client/jni/DEPS +++ b/remoting/client/jni/DEPS @@ -1,3 +1,4 @@ include_rules = [ + "+jni", "+ui/gfx/android", ] diff --git a/remoting/client/jni/chromoting_jni_onload.cc b/remoting/client/jni/chromoting_jni_onload.cc new file mode 100644 index 0000000..e82b757 --- /dev/null +++ b/remoting/client/jni/chromoting_jni_onload.cc @@ -0,0 +1,32 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/android/base_jni_registrar.h" +#include "base/android/jni_android.h" +#include "base/android/jni_registrar.h" +#include "net/android/net_jni_registrar.h" +#include "remoting/client/jni/chromoting_jni_runtime.h" +#include "ui/gfx/android/gfx_jni_registrar.h" + +extern "C" { + +JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { + base::android::InitVM(vm); + + JNIEnv* env = base::android::AttachCurrentThread(); + static base::android::RegistrationMethod kRemotingRegisteredMethods[] = { + {"base", base::android::RegisterJni}, + {"gfx", gfx::android::RegisterJni}, + {"net", net::android::RegisterJni}, + {"remoting", remoting::RegisterJni}, + }; + if (!base::android::RegisterNativeMethods( + env, kRemotingRegisteredMethods, arraysize(kRemotingRegisteredMethods))) { + return -1; + } + + return JNI_VERSION_1_4; +} + +} // extern "C" diff --git a/remoting/client/jni/chromoting_jni_runtime.cc b/remoting/client/jni/chromoting_jni_runtime.cc index 11ca730..6b531fa 100644 --- a/remoting/client/jni/chromoting_jni_runtime.cc +++ b/remoting/client/jni/chromoting_jni_runtime.cc @@ -4,21 +4,23 @@ #include "remoting/client/jni/chromoting_jni_runtime.h" -#include "base/android/base_jni_registrar.h" #include "base/android/jni_android.h" +#include "base/android/jni_string.h" #include "base/android/scoped_java_ref.h" +#include "base/basictypes.h" +#include "base/command_line.h" #include "base/memory/singleton.h" #include "base/stl_util.h" #include "base/synchronization/waitable_event.h" +#include "google_apis/google_api_keys.h" +#include "jni/JniInterface_jni.h" #include "media/base/yuv_convert.h" -#include "net/android/net_jni_registrar.h" #include "remoting/base/url_request_context.h" #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" -namespace { +using base::android::ConvertJavaStringToUTF8; -// Class and package name of the Java class supporting the methods we call. -const char* const kJavaClass = "org/chromium/chromoting/jni/JniInterface"; +namespace { const int kBytesPerPixel = 4; @@ -26,22 +28,110 @@ const int kBytesPerPixel = 4; namespace remoting { +bool RegisterJni(JNIEnv* env) { + return remoting::RegisterNativesImpl(env); +} + +// Implementation of stubs defined in JniInterface_jni.h. These are the entry +// points for JNI calls from Java into C++. + +static void LoadNative(JNIEnv* env, jclass clazz, jobject context) { + base::android::ScopedJavaLocalRef<jobject> context_activity(env, context); + base::android::InitApplicationContext(context_activity); + + // The google_apis functions check the command-line arguments to make sure no + // runtime API keys have been specified by the environment. Unfortunately, we + // neither launch Chromium nor have a command line, so we need to prevent + // them from DCHECKing out when they go looking. + CommandLine::Init(0, NULL); + + // Create the singleton now so that the Chromoting threads will be set up. + remoting::ChromotingJniRuntime::GetInstance(); +} + +static jstring GetApiKey(JNIEnv* env, jclass clazz) { + return env->NewStringUTF(google_apis::GetAPIKey().c_str()); +} + +static jstring GetClientId(JNIEnv* env, jclass clazz) { + return env->NewStringUTF( + google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING).c_str()); +} + +static jstring GetClientSecret(JNIEnv* env, jclass clazz) { + return env->NewStringUTF( + google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING).c_str()); +} + +static void Connect(JNIEnv* env, + jclass clazz, + jstring username, + jstring authToken, + jstring hostJid, + jstring hostId, + jstring hostPubkey, + jstring pairId, + jstring pairSecret) { + remoting::ChromotingJniRuntime::GetInstance()->ConnectToHost( + ConvertJavaStringToUTF8(env, username).c_str(), + ConvertJavaStringToUTF8(env, authToken).c_str(), + ConvertJavaStringToUTF8(env, hostJid).c_str(), + ConvertJavaStringToUTF8(env, hostId).c_str(), + ConvertJavaStringToUTF8(env, hostPubkey).c_str(), + ConvertJavaStringToUTF8(env, pairId).c_str(), + ConvertJavaStringToUTF8(env, pairSecret).c_str()); +} + +static void Disconnect(JNIEnv* env, jclass clazz) { + remoting::ChromotingJniRuntime::GetInstance()->DisconnectFromHost(); +} + +static void AuthenticationResponse(JNIEnv* env, + jclass clazz, + jstring pin, + jboolean createPair) { + remoting::ChromotingJniRuntime::GetInstance()->session()->ProvideSecret( + ConvertJavaStringToUTF8(env, pin).c_str(), createPair); +} + +static void ScheduleRedraw(JNIEnv* env, jclass clazz) { + remoting::ChromotingJniRuntime::GetInstance()->session()->RedrawDesktop(); +} + +static void MouseAction(JNIEnv* env, + jclass clazz, + jint x, + jint y, + jint whichButton, + jboolean buttonDown) { + // Button must be within the bounds of the MouseEvent_MouseButton enum. + DCHECK(whichButton >= 0 && whichButton < 5); + + remoting::ChromotingJniRuntime::GetInstance()->session()->PerformMouseAction( + x, + y, + static_cast<remoting::protocol::MouseEvent_MouseButton>(whichButton), + buttonDown); +} + +static void KeyboardAction(JNIEnv* env, + jclass clazz, + jint keyCode, + jboolean keyDown) { + remoting::ChromotingJniRuntime::GetInstance() + ->session() + ->PerformKeyboardAction(keyCode, keyDown); +} + +// ChromotingJniRuntime implementation. + // static ChromotingJniRuntime* ChromotingJniRuntime::GetInstance() { return Singleton<ChromotingJniRuntime>::get(); } ChromotingJniRuntime::ChromotingJniRuntime() { - // Obtain a reference to the Java environment. (Future calls to this function - // made from the same thread return the same stored reference instead of - // repeating the work of attaching to the JVM.) - JNIEnv* env = base::android::AttachCurrentThread(); - - // The base and networks stacks must be registered with JNI in order to work - // on Android. An AtExitManager cleans this up at process exit. at_exit_manager_.reset(new base::AtExitManager()); - base::android::RegisterJni(env); - net::android::RegisterJni(env); // On Android, the UI thread is managed by Java, so we need to attach and // start a special type of message loop to allow Chromium code to run tasks. @@ -63,8 +153,6 @@ ChromotingJniRuntime::ChromotingJniRuntime() { // Allows later decoding of video frames. media::InitializeCPUSpecificYUVConversions(); - - class_ = static_cast<jclass>(env->NewGlobalRef(env->FindClass(kJavaClass))); } ChromotingJniRuntime::~ChromotingJniRuntime() { @@ -75,9 +163,6 @@ ChromotingJniRuntime::~ChromotingJniRuntime() { // components' still being alive. DisconnectFromHost(); - JNIEnv* env = base::android::AttachCurrentThread(); - env->DeleteGlobalRef(class_); - base::WaitableEvent done_event(false, false); network_task_runner_->PostTask(FROM_HERE, base::Bind( &ChromotingJniRuntime::DetachFromVmAndSignal, @@ -125,21 +210,14 @@ void ChromotingJniRuntime::ReportConnectionStatus( DCHECK(ui_task_runner_->BelongsToCurrentThread()); JNIEnv* env = base::android::AttachCurrentThread(); - env->CallStaticVoidMethod( - class_, - env->GetStaticMethodID(class_, "reportConnectionStatus", "(II)V"), - state, - error); + Java_JniInterface_reportConnectionStatus(env, state, error); } void ChromotingJniRuntime::DisplayAuthenticationPrompt(bool pairing_supported) { DCHECK(ui_task_runner_->BelongsToCurrentThread()); JNIEnv* env = base::android::AttachCurrentThread(); - env->CallStaticVoidMethod( - class_, - env->GetStaticMethodID(class_, "displayAuthenticationPrompt", "(Z)V"), - pairing_supported); + Java_JniInterface_displayAuthenticationPrompt(env, pairing_supported); } void ChromotingJniRuntime::CommitPairingCredentials(const std::string& host, @@ -156,15 +234,8 @@ void ChromotingJniRuntime::CommitPairingCredentials(const std::string& host, env->SetByteArrayRegion(secret_arr, 0, secret.size(), reinterpret_cast<const jbyte*>(secret.c_str())); - env->CallStaticVoidMethod( - class_, - env->GetStaticMethodID( - class_, - "commitPairingCredentials", - "(Ljava/lang/String;[B[B)V"), - host_jstr, - id_arr, - secret_arr); + Java_JniInterface_commitPairingCredentials(env, host_jstr, id_arr, + secret_arr); // Because we passed them as arguments, their corresponding Java objects were // GCd as soon as the managed method returned, so we mustn't release it here. @@ -173,30 +244,14 @@ void ChromotingJniRuntime::CommitPairingCredentials(const std::string& host, base::android::ScopedJavaLocalRef<jobject> ChromotingJniRuntime::NewBitmap( webrtc::DesktopSize size) { JNIEnv* env = base::android::AttachCurrentThread(); - - jobject bitmap = env->CallStaticObjectMethod( - class_, - env->GetStaticMethodID( - class_, - "newBitmap", - "(II)Landroid/graphics/Bitmap;"), - size.width(), - size.height()); - return base::android::ScopedJavaLocalRef<jobject>(env, bitmap); + return Java_JniInterface_newBitmap(env, size.width(), size.height()); } void ChromotingJniRuntime::UpdateFrameBitmap(jobject bitmap) { DCHECK(display_task_runner_->BelongsToCurrentThread()); JNIEnv* env = base::android::AttachCurrentThread(); - - env->CallStaticVoidMethod( - class_, - env->GetStaticMethodID( - class_, - "setVideoFrame", - "(Landroid/graphics/Bitmap;)V"), - bitmap); + Java_JniInterface_setVideoFrame(env, bitmap); } void ChromotingJniRuntime::UpdateCursorShape( @@ -214,26 +269,19 @@ void ChromotingJniRuntime::UpdateCursorShape( JNIEnv* env = base::android::AttachCurrentThread(); base::android::ScopedJavaLocalRef<jobject> buffer(env, env->NewDirectByteBuffer(data, cursor_total_bytes)); - env->CallStaticVoidMethod( - class_, - env->GetStaticMethodID( - class_, - "updateCursorShape", - "(IIIILjava/nio/ByteBuffer;)V"), - cursor_shape.width(), - cursor_shape.height(), - cursor_shape.hotspot_x(), - cursor_shape.hotspot_y(), - buffer.obj()); + Java_JniInterface_updateCursorShape(env, + cursor_shape.width(), + cursor_shape.height(), + cursor_shape.hotspot_x(), + cursor_shape.hotspot_y(), + buffer.obj()); } void ChromotingJniRuntime::RedrawCanvas() { DCHECK(display_task_runner_->BelongsToCurrentThread()); JNIEnv* env = base::android::AttachCurrentThread(); - env->CallStaticVoidMethod( - class_, - env->GetStaticMethodID(class_, "redrawGraphicsInternal", "()V")); + Java_JniInterface_redrawGraphicsInternal(env); } void ChromotingJniRuntime::DetachFromVmAndSignal(base::WaitableEvent* waiter) { diff --git a/remoting/client/jni/chromoting_jni_runtime.h b/remoting/client/jni/chromoting_jni_runtime.h index 93d77bd..bb356a1 100644 --- a/remoting/client/jni/chromoting_jni_runtime.h +++ b/remoting/client/jni/chromoting_jni_runtime.h @@ -19,6 +19,8 @@ template<typename T> struct DefaultSingletonTraits; namespace remoting { +bool RegisterJni(JNIEnv* env); + // Houses the global resources on which the Chromoting components run // (e.g. message loops and task runners). Proxies outgoing JNI calls from its // ChromotingJniInstance member to Java. All its methods should be invoked @@ -107,9 +109,6 @@ class ChromotingJniRuntime { // Detaches JVM from the current thread, then signals. Doesn't own |waiter|. void DetachFromVmAndSignal(base::WaitableEvent* waiter); - // Reference to the Java class into which we make JNI calls. - jclass class_; - // Used by the Chromium libraries to clean up the base and net libraries' JNI // bindings. It must persist for the lifetime of the singleton. scoped_ptr<base::AtExitManager> at_exit_manager_; diff --git a/remoting/client/jni/jni_interface.cc b/remoting/client/jni/jni_interface.cc deleted file mode 100644 index 5180558..0000000 --- a/remoting/client/jni/jni_interface.cc +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// This file defines functions that implement the static methods declared in a -// closely-related Java class in the platform-specific user interface -// implementation. In effect, it is the entry point for all JNI calls *into* -// the C++ codebase from Java. The separate ChromotingJniRuntime class serves -// as the corresponding exit point, and is responsible for making all JNI calls -// *out of* the C++ codebase into Java. - -#include <jni.h> - -#include "base/android/jni_android.h" -#include "base/command_line.h" -#include "base/memory/ref_counted.h" -#include "google_apis/google_api_keys.h" -#include "remoting/client/jni/chromoting_jni_instance.h" -#include "remoting/client/jni/chromoting_jni_runtime.h" - -// Class and package name of the Java class that declares this file's functions. -#define JNI_IMPLEMENTATION(method) \ - Java_org_chromium_chromoting_jni_JniInterface_##method - -extern "C" { - -JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { - base::android::InitVM(vm); - return JNI_VERSION_1_2; -} - -JNIEXPORT void JNICALL JNI_IMPLEMENTATION(loadNative)(JNIEnv* env, - jobject that, - jobject context) { - base::android::ScopedJavaLocalRef<jobject> context_activity(env, context); - base::android::InitApplicationContext(context_activity); - - // The google_apis functions check the command-line arguments to make sure no - // runtime API keys have been specified by the environment. Unfortunately, we - // neither launch Chromium nor have a command line, so we need to prevent - // them from DCHECKing out when they go looking. - CommandLine::Init(0, NULL); - - // Create the singleton now so that the Chromoting threads will be set up. - remoting::ChromotingJniRuntime::GetInstance(); -} - -JNIEXPORT jstring JNICALL JNI_IMPLEMENTATION(getApiKey)(JNIEnv* env, - jobject that) { - return env->NewStringUTF(google_apis::GetAPIKey().c_str()); -} - -JNIEXPORT jstring JNICALL JNI_IMPLEMENTATION(getClientId)(JNIEnv* env, - jobject that) { - return env->NewStringUTF( - google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING).c_str()); -} - -JNIEXPORT jstring JNICALL JNI_IMPLEMENTATION(getClientSecret)(JNIEnv* env, - jobject that) { - return env->NewStringUTF( - google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING).c_str()); -} - -JNIEXPORT void JNICALL JNI_IMPLEMENTATION(connectNative)( - JNIEnv* env, - jobject that, - jstring username_jstr, - jstring auth_token_jstr, - jstring host_jid_jstr, - jstring host_id_jstr, - jstring host_pubkey_jstr, - jstring pair_id_jstr, - jstring pair_secret_jstr) { - const char* username_cstr = env->GetStringUTFChars(username_jstr, NULL); - const char* auth_token_cstr = env->GetStringUTFChars(auth_token_jstr, NULL); - const char* host_jid_cstr = env->GetStringUTFChars(host_jid_jstr, NULL); - const char* host_id_cstr = env->GetStringUTFChars(host_id_jstr, NULL); - const char* host_pubkey_cstr = env->GetStringUTFChars(host_pubkey_jstr, NULL); - const char* pair_id_cstr = env->GetStringUTFChars(pair_id_jstr, NULL); - const char* pair_secret_cstr = env->GetStringUTFChars(pair_secret_jstr, NULL); - - remoting::ChromotingJniRuntime::GetInstance()->ConnectToHost( - username_cstr, - auth_token_cstr, - host_jid_cstr, - host_id_cstr, - host_pubkey_cstr, - pair_id_cstr, - pair_secret_cstr); - - env->ReleaseStringUTFChars(username_jstr, username_cstr); - env->ReleaseStringUTFChars(auth_token_jstr, auth_token_cstr); - env->ReleaseStringUTFChars(host_jid_jstr, host_jid_cstr); - env->ReleaseStringUTFChars(host_id_jstr, host_id_cstr); - env->ReleaseStringUTFChars(host_pubkey_jstr, host_pubkey_cstr); - env->ReleaseStringUTFChars(pair_id_jstr, pair_id_cstr); - env->ReleaseStringUTFChars(pair_secret_jstr, pair_secret_cstr); -} - -JNIEXPORT void JNICALL JNI_IMPLEMENTATION(disconnectNative)(JNIEnv* env, - jobject that) { - remoting::ChromotingJniRuntime::GetInstance()->DisconnectFromHost(); -} - -JNIEXPORT void JNICALL JNI_IMPLEMENTATION(authenticationResponse)( - JNIEnv* env, - jobject that, - jstring pin_jstr, - jboolean create_pair) { - const char* pin_cstr = env->GetStringUTFChars(pin_jstr, NULL); - - remoting::ChromotingJniRuntime::GetInstance()-> - session()->ProvideSecret(pin_cstr, create_pair); - - env->ReleaseStringUTFChars(pin_jstr, pin_cstr); -} - -JNIEXPORT void JNICALL JNI_IMPLEMENTATION(scheduleRedrawNative)( - JNIEnv* env, - jobject that) { - remoting::ChromotingJniRuntime::GetInstance()->session()->RedrawDesktop(); -} - -JNIEXPORT void JNICALL JNI_IMPLEMENTATION(mouseActionNative)( - JNIEnv* env, - jobject that, - jint x, - jint y, - jint which_button, - jboolean button_down) { - // Button must be within the bounds of the MouseEvent_MouseButton enum. - DCHECK(which_button >= 0 && which_button < 5); - - remoting::ChromotingJniRuntime::GetInstance()->session()->PerformMouseAction( - x, - y, - static_cast<remoting::protocol::MouseEvent_MouseButton>(which_button), - button_down); -} - -JNIEXPORT void JNICALL JNI_IMPLEMENTATION(keyboardActionNative)( - JNIEnv* env, - jobject that, - jint key_code, - jboolean key_down) { - remoting::ChromotingJniRuntime::GetInstance()->session()-> - PerformKeyboardAction(key_code, key_down); -} - -} // extern "C" diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp index c268d99..a100022 100644 --- a/remoting/remoting.gyp +++ b/remoting/remoting.gyp @@ -1821,25 +1821,40 @@ ['OS=="android"', { 'targets': [ { + 'target_name': 'remoting_jni_headers', + 'type': 'none', + 'sources': [ + 'android/java/src/org/chromium/chromoting/jni/JniInterface.java', + ], + 'variables': { + 'jni_gen_package': 'remoting', + }, + 'includes': [ '../build/jni_generator.gypi' ], + }, # end of target 'remoting_jni_headers' + { 'target_name': 'remoting_client_jni', 'type': 'shared_library', 'dependencies': [ 'remoting_base', 'remoting_client', 'remoting_jingle_glue', + 'remoting_jni_headers', 'remoting_protocol', '../google_apis/google_apis.gyp:google_apis', ], + 'include_dirs': [ + '<(SHARED_INTERMEDIATE_DIR)/remoting', + ], 'sources': [ 'client/jni/android_keymap.cc', 'client/jni/android_keymap.h', 'client/jni/chromoting_jni_instance.cc', 'client/jni/chromoting_jni_instance.h', + 'client/jni/chromoting_jni_onload.cc', 'client/jni/chromoting_jni_runtime.cc', 'client/jni/chromoting_jni_runtime.h', 'client/jni/jni_frame_consumer.cc', 'client/jni/jni_frame_consumer.h', - 'client/jni/jni_interface.cc', ], }, # end of target 'remoting_client_jni' { |