Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chromoting.jni; | 5 package org.chromium.chromoting.jni; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 | 8 |
| 9 import org.chromium.base.ContextUtils; | 9 import org.chromium.base.ContextUtils; |
| 10 import org.chromium.base.Log; | 10 import org.chromium.base.Log; |
| 11 import org.chromium.base.annotations.CalledByNative; | 11 import org.chromium.base.annotations.CalledByNative; |
| 12 import org.chromium.base.annotations.JNINamespace; | 12 import org.chromium.base.annotations.JNINamespace; |
| 13 import org.chromium.chromoting.OAuthTokenConsumer; | 13 import org.chromium.chromoting.OAuthTokenConsumer; |
| 14 import org.chromium.chromoting.base.OAuthTokenFetcher; | 14 import org.chromium.chromoting.base.OAuthTokenFetcher; |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * Initializes the Chromium remoting library, and provides JNI calls into it. | 17 * Initializes the Chromium remoting library, and provides JNI calls into it. |
| 18 * All interaction with the native code is centralized in this class. | 18 * All interaction with the native code is centralized in this class. |
| 19 */ | 19 */ |
| 20 @JNINamespace("remoting") | 20 @JNINamespace("remoting") |
| 21 public class JniInterface { | 21 public class JniInterface { |
| 22 private static final String TAG = "Chromoting"; | 22 private static final String TAG = "Chromoting"; |
| 23 | 23 |
| 24 private static final String TOKEN_SCOPE = "oauth2:https://www.googleapis.com /auth/chromoting"; | 24 private static final String TOKEN_SCOPE = "oauth2:https://www.googleapis.com /auth/chromoting"; |
| 25 | 25 |
| 26 private static final String JNI_LIB_NAME = "remoting_client_jni"; | |
|
Lambros
2016/08/09 00:51:54
Maybe just LIBRARY_NAME ?
Yuwei
2016/08/09 00:56:17
Done.
| |
| 27 | |
| 26 // Used to fetch auth token for native client. | 28 // Used to fetch auth token for native client. |
| 27 private static OAuthTokenConsumer sLoggerTokenConsumer; | 29 private static OAuthTokenConsumer sLoggerTokenConsumer; |
| 28 | 30 |
| 29 private static String sAccount; | 31 private static String sAccount; |
| 30 | 32 |
| 31 /** | 33 /** |
| 32 * To be called once from the Application context singleton. Loads and initi alizes the native | 34 * To be called once from the Application context singleton. Loads and initi alizes the native |
| 33 * code. Called on the UI thread. | 35 * code. Called on the UI thread. |
| 34 * @param context The Application context. | 36 * @param context The Application context. |
| 35 */ | 37 */ |
| 36 public static void loadLibrary(Context context) { | 38 public static void loadLibrary(Context context) { |
| 37 ContextUtils.initApplicationContext(context.getApplicationContext()); | 39 ContextUtils.initApplicationContext(context.getApplicationContext()); |
| 38 sLoggerTokenConsumer = new OAuthTokenConsumer(context.getApplicationCont ext(), TOKEN_SCOPE); | 40 sLoggerTokenConsumer = new OAuthTokenConsumer(context.getApplicationCont ext(), TOKEN_SCOPE); |
| 39 System.loadLibrary("remoting_client_jni"); | 41 try { |
| 42 System.loadLibrary(JNI_LIB_NAME); | |
| 43 } catch (UnsatisfiedLinkError e) { | |
| 44 Log.w(TAG, "Couldn't load " + JNI_LIB_NAME + ", trying " + JNI_LIB_N AME + ".cr"); | |
| 45 System.loadLibrary(JNI_LIB_NAME + ".cr"); | |
| 46 } | |
| 40 ContextUtils.initApplicationContextForNative(); | 47 ContextUtils.initApplicationContextForNative(); |
| 41 nativeLoadNative(); | 48 nativeLoadNative(); |
| 42 } | 49 } |
| 43 | 50 |
| 44 public static void setAccountForLogging(String account) { | 51 public static void setAccountForLogging(String account) { |
| 45 sAccount = account; | 52 sAccount = account; |
| 46 } | 53 } |
| 47 | 54 |
| 48 @CalledByNative | 55 @CalledByNative |
| 49 private static void fetchAuthToken() { | 56 private static void fetchAuthToken() { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 62 } | 69 } |
| 63 }); | 70 }); |
| 64 } | 71 } |
| 65 | 72 |
| 66 /** Performs the native portion of the initialization. */ | 73 /** Performs the native portion of the initialization. */ |
| 67 private static native void nativeLoadNative(); | 74 private static native void nativeLoadNative(); |
| 68 | 75 |
| 69 /** Notifies the native client with the new auth token */ | 76 /** Notifies the native client with the new auth token */ |
| 70 private static native void nativeOnAuthTokenFetched(String token); | 77 private static native void nativeOnAuthTokenFetched(String token); |
| 71 } | 78 } |
| OLD | NEW |