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.app.Activity; | 7 import android.app.Activity; |
8 import android.app.AlertDialog; | 8 import android.app.AlertDialog; |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.content.DialogInterface; | 10 import android.content.DialogInterface; |
11 import android.content.SharedPreferences; | 11 import android.content.SharedPreferences; |
12 import android.graphics.Bitmap; | 12 import android.graphics.Bitmap; |
13 import android.graphics.Point; | 13 import android.graphics.Point; |
14 import android.os.Build; | 14 import android.os.Build; |
15 import android.os.Looper; | 15 import android.os.Looper; |
16 import android.util.Log; | 16 import android.util.Log; |
17 import android.view.KeyEvent; | 17 import android.view.KeyEvent; |
18 import android.view.View; | 18 import android.view.View; |
19 import android.widget.CheckBox; | 19 import android.widget.CheckBox; |
20 import android.widget.TextView; | 20 import android.widget.TextView; |
21 | 21 |
22 import org.chromium.base.CalledByNative; | 22 import org.chromium.base.CalledByNative; |
23 import org.chromium.base.JNINamespace; | 23 import org.chromium.base.JNINamespace; |
| 24 import org.chromium.chromoting.CapabilityManager; |
24 import org.chromium.chromoting.Chromoting; | 25 import org.chromium.chromoting.Chromoting; |
25 import org.chromium.chromoting.R; | 26 import org.chromium.chromoting.R; |
26 | 27 |
27 import java.nio.ByteBuffer; | 28 import java.nio.ByteBuffer; |
28 import java.nio.ByteOrder; | 29 import java.nio.ByteOrder; |
29 | 30 |
30 /** | 31 /** |
31 * Initializes the Chromium remoting library, and provides JNI calls into it. | 32 * Initializes the Chromium remoting library, and provides JNI calls into it. |
32 * All interaction with the native code is centralized in this class. | 33 * All interaction with the native code is centralized in this class. |
33 */ | 34 */ |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 | 136 |
136 /** Protects access to sFrameBitmap. */ | 137 /** Protects access to sFrameBitmap. */ |
137 private static final Object sFrameLock = new Object(); | 138 private static final Object sFrameLock = new Object(); |
138 | 139 |
139 /** Position of cursor hot-spot. Accessed on the graphics thread. */ | 140 /** Position of cursor hot-spot. Accessed on the graphics thread. */ |
140 private static Point sCursorHotspot = new Point(); | 141 private static Point sCursorHotspot = new Point(); |
141 | 142 |
142 /** Bitmap holding the cursor shape. Accessed on the graphics thread. */ | 143 /** Bitmap holding the cursor shape. Accessed on the graphics thread. */ |
143 private static Bitmap sCursorBitmap = null; | 144 private static Bitmap sCursorBitmap = null; |
144 | 145 |
| 146 /** Capability Manager through which capabilities and extensions are handled
. */ |
| 147 private static CapabilityManager sCapabilityManager = CapabilityManager.getI
nstance(); |
| 148 |
145 /** | 149 /** |
146 * To be called once from the main Activity. Any subsequent calls will updat
e the application | 150 * To be called once from the main Activity. Any subsequent calls will updat
e the application |
147 * context, but not reload the library. This is useful e.g. when the activit
y is closed and the | 151 * context, but not reload the library. This is useful e.g. when the activit
y is closed and the |
148 * user later wants to return to the application. Called on the UI thread. | 152 * user later wants to return to the application. Called on the UI thread. |
149 */ | 153 */ |
150 public static void loadLibrary(Activity context) { | 154 public static void loadLibrary(Activity context) { |
151 sContext = context; | 155 sContext = context; |
152 | 156 |
153 if (sLoaded) return; | 157 if (sLoaded) return; |
154 | 158 |
(...skipping 14 matching lines...) Expand all Loading... |
169 public static native String nativeGetClientSecret(); | 173 public static native String nativeGetClientSecret(); |
170 | 174 |
171 /** Attempts to form a connection to the user-selected host. Called on the U
I thread. */ | 175 /** Attempts to form a connection to the user-selected host. Called on the U
I thread. */ |
172 public static void connectToHost(String username, String authToken, | 176 public static void connectToHost(String username, String authToken, |
173 String hostJid, String hostId, String hostPubkey, ConnectionListener
listener) { | 177 String hostJid, String hostId, String hostPubkey, ConnectionListener
listener) { |
174 disconnectFromHost(); | 178 disconnectFromHost(); |
175 | 179 |
176 sConnectionListener = listener; | 180 sConnectionListener = listener; |
177 SharedPreferences prefs = sContext.getPreferences(Activity.MODE_PRIVATE)
; | 181 SharedPreferences prefs = sContext.getPreferences(Activity.MODE_PRIVATE)
; |
178 nativeConnect(username, authToken, hostJid, hostId, hostPubkey, | 182 nativeConnect(username, authToken, hostJid, hostId, hostPubkey, |
179 prefs.getString(hostId + "_id", ""), prefs.getString(hostId + "_
secret", "")); | 183 prefs.getString(hostId + "_id", ""), prefs.getString(hostId + "_secr
et", ""), |
| 184 sCapabilityManager.getLocalCapabilities()); |
180 sConnected = true; | 185 sConnected = true; |
181 } | 186 } |
182 | 187 |
183 /** Performs the native portion of the connection. */ | 188 /** Performs the native portion of the connection. */ |
184 private static native void nativeConnect(String username, String authToken,
String hostJid, | 189 private static native void nativeConnect( |
185 String hostId, String hostPubkey, String pairId, String pairSecret); | 190 String username, String authToken, String hostJid, String hostId, String
hostPubkey, |
| 191 String pairId, String pairSecret, String capabilities); |
186 | 192 |
187 /** Severs the connection and cleans up. Called on the UI thread. */ | 193 /** Severs the connection and cleans up. Called on the UI thread. */ |
188 public static void disconnectFromHost() { | 194 public static void disconnectFromHost() { |
189 if (!sConnected) return; | 195 if (!sConnected) return; |
190 | 196 |
191 sConnectionListener.onConnectionState(ConnectionListener.State.CLOSED, | 197 sConnectionListener.onConnectionState(ConnectionListener.State.CLOSED, |
192 ConnectionListener.Error.OK); | 198 ConnectionListener.Error.OK); |
193 | 199 |
194 nativeDisconnect(); | 200 nativeDisconnect(); |
195 sConnectionListener = null; | 201 sConnectionListener = null; |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 @CalledByNative | 457 @CalledByNative |
452 public static void fetchThirdPartyToken(String tokenUrl, String clientId, St
ring scope) { | 458 public static void fetchThirdPartyToken(String tokenUrl, String clientId, St
ring scope) { |
453 Chromoting app = (Chromoting) sContext; | 459 Chromoting app = (Chromoting) sContext; |
454 app.fetchThirdPartyToken(tokenUrl, clientId, scope); | 460 app.fetchThirdPartyToken(tokenUrl, clientId, scope); |
455 } | 461 } |
456 | 462 |
457 /** | 463 /** |
458 * Notify the native code to continue authentication with the |token| and th
e |sharedSecret|. | 464 * Notify the native code to continue authentication with the |token| and th
e |sharedSecret|. |
459 */ | 465 */ |
460 public static native void nativeOnThirdPartyTokenFetched(String token, Strin
g sharedSecret); | 466 public static native void nativeOnThirdPartyTokenFetched(String token, Strin
g sharedSecret); |
| 467 |
| 468 // |
| 469 // Host and Client Capabilities |
| 470 // |
| 471 |
| 472 /** Set the list of negotiated capabilities between host and client. Called
on the UI thread. */ |
| 473 @CalledByNative |
| 474 public static void setCapabilities(String capabilities) { |
| 475 sCapabilityManager.setNegotiatedCapabilities(capabilities); |
| 476 } |
| 477 |
| 478 // |
| 479 // Extension Message Handling |
| 480 // |
| 481 |
| 482 /** Passes on the deconstructed ExtensionMessage to the app. Called on the U
I thread. */ |
| 483 @CalledByNative |
| 484 public static void handleExtensionMessage(String type, String data) { |
| 485 sCapabilityManager.onExtensionMessage(type, data); |
| 486 } |
| 487 |
| 488 |
| 489 public static void sendExtensionMessage(String type, String data) { |
| 490 if (!sConnected) |
| 491 return; |
| 492 |
| 493 nativeSendExtensionMessage(type, data); |
| 494 } |
| 495 |
| 496 public static native void nativeSendExtensionMessage(String type, String dat
a); |
461 } | 497 } |
OLD | NEW |