OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.graphics.Bitmap; | 7 import android.graphics.Bitmap; |
8 import android.graphics.Point; | 8 import android.graphics.Point; |
9 import android.os.Looper; | 9 import android.os.Looper; |
10 | 10 |
11 import org.chromium.base.Log; | 11 import org.chromium.base.Log; |
| 12 import org.chromium.base.annotations.CalledByNative; |
12 import org.chromium.base.annotations.JNINamespace; | 13 import org.chromium.base.annotations.JNINamespace; |
13 import org.chromium.base.annotations.SuppressFBWarnings; | 14 import org.chromium.base.annotations.SuppressFBWarnings; |
14 import org.chromium.chromoting.CapabilityManager; | 15 import org.chromium.chromoting.CapabilityManager; |
15 import org.chromium.chromoting.SessionAuthenticator; | 16 import org.chromium.chromoting.SessionAuthenticator; |
16 | 17 |
17 import java.nio.ByteBuffer; | 18 import java.nio.ByteBuffer; |
18 import java.nio.ByteOrder; | 19 import java.nio.ByteOrder; |
19 | 20 |
20 /** | 21 /** |
21 * Class to manage a client connection to the host. This class controls the life
time of the | 22 * Class to manage a client connection to the host. This class controls the life
time of the |
(...skipping 15 matching lines...) Expand all Loading... |
37 // Called on the UI thread. | 38 // Called on the UI thread. |
38 public Client() { | 39 public Client() { |
39 if (sClient != null) { | 40 if (sClient != null) { |
40 throw new RuntimeException("Client instance already created."); | 41 throw new RuntimeException("Client instance already created."); |
41 } | 42 } |
42 | 43 |
43 sClient = this; | 44 sClient = this; |
44 mNativeJniClient = nativeInit(); | 45 mNativeJniClient = nativeInit(); |
45 } | 46 } |
46 | 47 |
47 private native long nativeInit(); | |
48 | |
49 // Called on the UI thread. Suppress FindBugs warning, since |sClient| is on
ly used on the | 48 // Called on the UI thread. Suppress FindBugs warning, since |sClient| is on
ly used on the |
50 // UI thread. | 49 // UI thread. |
51 @SuppressFBWarnings("LI_LAZY_INIT_STATIC") | 50 @SuppressFBWarnings("LI_LAZY_INIT_STATIC") |
52 public void destroy() { | 51 public void destroy() { |
53 if (sClient != null) { | 52 if (sClient != null) { |
54 disconnectFromHost(); | 53 disconnectFromHost(); |
55 nativeDestroy(mNativeJniClient); | 54 nativeDestroy(mNativeJniClient); |
56 sClient = null; | 55 sClient = null; |
57 } | 56 } |
58 } | 57 } |
59 | 58 |
60 private native void nativeDestroy(long nativeJniClient); | |
61 | |
62 /** Returns the current Client instance, or null. */ | 59 /** Returns the current Client instance, or null. */ |
63 public static Client getInstance() { | 60 public static Client getInstance() { |
64 return sClient; | 61 return sClient; |
65 } | 62 } |
66 | 63 |
67 /** Used for authentication-related UX during connection. Accessed on the UI
thread. */ | 64 /** Used for authentication-related UX during connection. Accessed on the UI
thread. */ |
68 private SessionAuthenticator mAuthenticator; | 65 private SessionAuthenticator mAuthenticator; |
69 | 66 |
70 /** Whether the native code is attempting a connection. Accessed on the UI t
hread. */ | 67 /** Whether the native code is attempting a connection. Accessed on the UI t
hread. */ |
71 private boolean mConnected; | 68 private boolean mConnected; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 } | 101 } |
105 | 102 |
106 /** Attempts to form a connection to the user-selected host. Called on the U
I thread. */ | 103 /** Attempts to form a connection to the user-selected host. Called on the U
I thread. */ |
107 public void connectToHost(String username, String authToken, String hostJid, | 104 public void connectToHost(String username, String authToken, String hostJid, |
108 String hostId, String hostPubkey, SessionAuthenticator authenticator
, String flags, | 105 String hostId, String hostPubkey, SessionAuthenticator authenticator
, String flags, |
109 ConnectionListener listener) { | 106 ConnectionListener listener) { |
110 disconnectFromHost(); | 107 disconnectFromHost(); |
111 | 108 |
112 mConnectionListener = listener; | 109 mConnectionListener = listener; |
113 mAuthenticator = authenticator; | 110 mAuthenticator = authenticator; |
114 JniInterface.nativeConnect(username, authToken, hostJid, hostId, hostPub
key, | 111 nativeConnect(mNativeJniClient, username, authToken, hostJid, hostId, ho
stPubkey, |
115 mAuthenticator.getPairingId(hostId), mAuthenticator.getPairingSe
cret(hostId), | 112 mAuthenticator.getPairingId(hostId), mAuthenticator.getPairingSe
cret(hostId), |
116 mCapabilityManager.getLocalCapabilities(), flags); | 113 mCapabilityManager.getLocalCapabilities(), flags); |
117 mConnected = true; | 114 mConnected = true; |
118 } | 115 } |
119 | 116 |
120 /** Severs the connection and cleans up. Called on the UI thread. */ | 117 /** Severs the connection and cleans up. Called on the UI thread. */ |
121 public void disconnectFromHost() { | 118 public void disconnectFromHost() { |
122 if (!mConnected) { | 119 if (!mConnected) { |
123 return; | 120 return; |
124 } | 121 } |
125 | 122 |
126 mConnectionListener.onConnectionState( | 123 mConnectionListener.onConnectionState( |
127 ConnectionListener.State.CLOSED, ConnectionListener.Error.OK); | 124 ConnectionListener.State.CLOSED, ConnectionListener.Error.OK); |
128 | 125 |
129 disconnectFromHostWithoutNotification(); | 126 disconnectFromHostWithoutNotification(); |
130 } | 127 } |
131 | 128 |
132 /** Same as disconnectFromHost() but without notifying the ConnectionListene
r. */ | 129 /** Same as disconnectFromHost() but without notifying the ConnectionListene
r. */ |
133 private void disconnectFromHostWithoutNotification() { | 130 private void disconnectFromHostWithoutNotification() { |
134 if (!mConnected) { | 131 if (!mConnected) { |
135 return; | 132 return; |
136 } | 133 } |
137 | 134 |
138 JniInterface.nativeDisconnect(); | 135 nativeDisconnect(mNativeJniClient); |
139 mConnectionListener = null; | 136 mConnectionListener = null; |
140 mConnected = false; | 137 mConnected = false; |
141 mCapabilityManager.onHostDisconnect(); | 138 mCapabilityManager.onHostDisconnect(); |
142 | 139 |
143 // Drop the reference to free the Bitmap for GC. | 140 // Drop the reference to free the Bitmap for GC. |
144 synchronized (mFrameLock) { | 141 synchronized (mFrameLock) { |
145 mFrameBitmap = null; | 142 mFrameBitmap = null; |
146 } | 143 } |
147 } | 144 } |
148 | 145 |
149 /** Called by native code whenever the connection status changes. Called on
the UI thread. */ | 146 /** Called on the UI thread whenever the connection status changes. */ |
| 147 @CalledByNative |
150 void onConnectionState(int stateCode, int errorCode) { | 148 void onConnectionState(int stateCode, int errorCode) { |
151 ConnectionListener.State state = ConnectionListener.State.fromValue(stat
eCode); | 149 ConnectionListener.State state = ConnectionListener.State.fromValue(stat
eCode); |
152 ConnectionListener.Error error = ConnectionListener.Error.fromValue(erro
rCode); | 150 ConnectionListener.Error error = ConnectionListener.Error.fromValue(erro
rCode); |
153 mConnectionListener.onConnectionState(state, error); | 151 mConnectionListener.onConnectionState(state, error); |
154 if (state == ConnectionListener.State.FAILED || state == ConnectionListe
ner.State.CLOSED) { | 152 if (state == ConnectionListener.State.FAILED || state == ConnectionListe
ner.State.CLOSED) { |
155 // Disconnect from the host here, otherwise the next time connectToH
ost() is called, | 153 // Disconnect from the host here, otherwise the next time connectToH
ost() is called, |
156 // it will try to disconnect, triggering an incorrect status notific
ation. | 154 // it will try to disconnect, triggering an incorrect status notific
ation. |
157 | 155 |
158 // TODO(lambroslambrou): Connection state notifications for separate
sessions should | 156 // TODO(lambroslambrou): Connection state notifications for separate
sessions should |
159 // go to separate Client instances. Once this is true, we can remove
this line and | 157 // go to separate Client instances. Once this is true, we can remove
this line and |
160 // simplify the disconnectFromHost() code. | 158 // simplify the disconnectFromHost() code. |
161 disconnectFromHostWithoutNotification(); | 159 disconnectFromHostWithoutNotification(); |
162 } | 160 } |
163 } | 161 } |
164 | 162 |
165 /** | 163 /** |
166 * Called by JniInterface (from native code) to prompt the user to enter a P
IN. Called on the | 164 * Called on the UI thread to prompt the user to enter a PIN. |
167 * UI thread. | |
168 */ | 165 */ |
| 166 @CalledByNative |
169 void displayAuthenticationPrompt(boolean pairingSupported) { | 167 void displayAuthenticationPrompt(boolean pairingSupported) { |
170 mAuthenticator.displayAuthenticationPrompt(pairingSupported); | 168 mAuthenticator.displayAuthenticationPrompt(pairingSupported); |
171 } | 169 } |
172 | 170 |
173 /** | 171 /** |
174 * Called by the SessionAuthenticator after the user enters a PIN. | 172 * Called by the SessionAuthenticator after the user enters a PIN. |
175 * @param pin The entered PIN. | 173 * @param pin The entered PIN. |
176 * @param createPair Whether to create a new pairing for this client. | 174 * @param createPair Whether to create a new pairing for this client. |
177 * @param deviceName The device name to appear in the pairing registry. Only
used if createPair | 175 * @param deviceName The device name to appear in the pairing registry. Only
used if createPair |
178 * is true. | 176 * is true. |
179 */ | 177 */ |
180 public void handleAuthenticationResponse( | 178 public void handleAuthenticationResponse( |
181 String pin, boolean createPair, String deviceName) { | 179 String pin, boolean createPair, String deviceName) { |
182 assert mConnected; | 180 assert mConnected; |
183 JniInterface.nativeAuthenticationResponse(pin, createPair, deviceName); | 181 nativeAuthenticationResponse(mNativeJniClient, pin, createPair, deviceNa
me); |
184 } | 182 } |
185 | 183 |
186 /** | 184 /** |
187 * Called by JniInterface (from native code), to save newly-received pairing
credentials to | 185 * Called on the UI thread to save newly-received pairing credentials to per
manent storage. |
188 * permanent storage. Called on the UI thread. | |
189 */ | 186 */ |
| 187 @CalledByNative |
190 void commitPairingCredentials(String host, String id, String secret) { | 188 void commitPairingCredentials(String host, String id, String secret) { |
191 mAuthenticator.commitPairingCredentials(host, id, secret); | 189 mAuthenticator.commitPairingCredentials(host, id, secret); |
192 } | 190 } |
193 | 191 |
194 /** | 192 /** |
195 * Moves the mouse cursor, possibly while clicking the specified (nonnegativ
e) button. Called | 193 * Moves the mouse cursor, possibly while clicking the specified (nonnegativ
e) button. Called |
196 * on the UI thread. | 194 * on the UI thread. |
197 */ | 195 */ |
198 public void sendMouseEvent(int x, int y, int whichButton, boolean buttonDown
) { | 196 public void sendMouseEvent(int x, int y, int whichButton, boolean buttonDown
) { |
199 if (!mConnected) { | 197 if (!mConnected) { |
200 return; | 198 return; |
201 } | 199 } |
202 | 200 |
203 JniInterface.nativeSendMouseEvent(x, y, whichButton, buttonDown); | 201 nativeSendMouseEvent(mNativeJniClient, x, y, whichButton, buttonDown); |
204 } | 202 } |
205 | 203 |
206 /** Injects a mouse-wheel event with delta values. Called on the UI thread.
*/ | 204 /** Injects a mouse-wheel event with delta values. Called on the UI thread.
*/ |
207 public void sendMouseWheelEvent(int deltaX, int deltaY) { | 205 public void sendMouseWheelEvent(int deltaX, int deltaY) { |
208 if (!mConnected) { | 206 if (!mConnected) { |
209 return; | 207 return; |
210 } | 208 } |
211 | 209 |
212 JniInterface.nativeSendMouseWheelEvent(deltaX, deltaY); | 210 nativeSendMouseWheelEvent(mNativeJniClient, deltaX, deltaY); |
213 } | 211 } |
214 | 212 |
215 /** | 213 /** |
216 * Presses or releases the specified key. Called on the UI thread. If scanCo
de is not zero then | 214 * Presses or releases the specified key. Called on the UI thread. If scanCo
de is not zero then |
217 * keyCode is ignored. | 215 * keyCode is ignored. |
218 */ | 216 */ |
219 public boolean sendKeyEvent(int scanCode, int keyCode, boolean keyDown) { | 217 public boolean sendKeyEvent(int scanCode, int keyCode, boolean keyDown) { |
220 if (!mConnected) { | 218 if (!mConnected) { |
221 return false; | 219 return false; |
222 } | 220 } |
223 | 221 |
224 return JniInterface.nativeSendKeyEvent(scanCode, keyCode, keyDown); | 222 return nativeSendKeyEvent(mNativeJniClient, scanCode, keyCode, keyDown); |
225 } | 223 } |
226 | 224 |
227 /** Sends TextEvent to the host. Called on the UI thread. */ | 225 /** Sends TextEvent to the host. Called on the UI thread. */ |
228 public void sendTextEvent(String text) { | 226 public void sendTextEvent(String text) { |
229 if (!mConnected) { | 227 if (!mConnected) { |
230 return; | 228 return; |
231 } | 229 } |
232 | 230 |
233 JniInterface.nativeSendTextEvent(text); | 231 nativeSendTextEvent(mNativeJniClient, text); |
234 } | 232 } |
235 | 233 |
236 /** Sends an array of TouchEvents to the host. Called on the UI thread. */ | 234 /** Sends an array of TouchEvents to the host. Called on the UI thread. */ |
237 public void sendTouchEvent(TouchEventData.EventType eventType, TouchEventDat
a[] data) { | 235 public void sendTouchEvent(TouchEventData.EventType eventType, TouchEventDat
a[] data) { |
238 if (!mConnected) { | 236 if (!mConnected) { |
239 return; | 237 return; |
240 } | 238 } |
241 | 239 |
242 JniInterface.nativeSendTouchEvent(eventType.value(), data); | 240 nativeSendTouchEvent(mNativeJniClient, eventType.value(), data); |
243 } | 241 } |
244 | 242 |
245 /** | 243 /** |
246 * Enables or disables the video channel. Called on the UI thread in respons
e to Activity | 244 * Enables or disables the video channel. Called on the UI thread in respons
e to Activity |
247 * lifecycle events. | 245 * lifecycle events. |
248 */ | 246 */ |
249 public void enableVideoChannel(boolean enable) { | 247 public void enableVideoChannel(boolean enable) { |
250 if (!mConnected) { | 248 if (!mConnected) { |
251 return; | 249 return; |
252 } | 250 } |
253 | 251 |
254 JniInterface.nativeEnableVideoChannel(enable); | 252 nativeEnableVideoChannel(mNativeJniClient, enable); |
255 } | 253 } |
256 | 254 |
257 /** | 255 /** |
258 * Sets the redraw callback to the provided functor. Provide a value of null
whenever the | 256 * Sets the redraw callback to the provided functor. Provide a value of null
whenever the |
259 * window is no longer visible so that we don't continue to draw onto it. Ca
lled on the UI | 257 * window is no longer visible so that we don't continue to draw onto it. Ca
lled on the UI |
260 * thread. | 258 * thread. |
261 */ | 259 */ |
262 public void provideRedrawCallback(Runnable redrawCallback) { | 260 public void provideRedrawCallback(Runnable redrawCallback) { |
263 mRedrawCallback = redrawCallback; | 261 mRedrawCallback = redrawCallback; |
264 } | 262 } |
265 | 263 |
266 /** Forces the native graphics thread to redraw to the canvas. Called on the
UI thread. */ | 264 /** Forces the native graphics thread to redraw to the canvas. Called on the
UI thread. */ |
267 public boolean redrawGraphics() { | 265 public boolean redrawGraphics() { |
268 if (!mConnected || mRedrawCallback == null) return false; | 266 if (!mConnected || mRedrawCallback == null) return false; |
269 | 267 |
270 JniInterface.nativeScheduleRedraw(); | 268 nativeScheduleRedraw(mNativeJniClient); |
271 return true; | 269 return true; |
272 } | 270 } |
273 | 271 |
274 /** | 272 /** |
275 * Called by JniInterface to perform the redrawing callback requested by | 273 * Called on the graphics thread to perform the redrawing callback requested
by |
276 * {@link #redrawGraphics}. This is a no-op if the window isn't visible (the
callback is null). | 274 * {@link #redrawGraphics}. This is a no-op if the window isn't visible (the
callback is null). |
277 * Called on the graphics thread. | |
278 */ | 275 */ |
| 276 @CalledByNative |
279 void redrawGraphicsInternal() { | 277 void redrawGraphicsInternal() { |
280 Runnable callback = mRedrawCallback; | 278 Runnable callback = mRedrawCallback; |
281 if (callback != null) { | 279 if (callback != null) { |
282 callback.run(); | 280 callback.run(); |
283 } | 281 } |
284 } | 282 } |
285 | 283 |
286 /** | 284 /** |
287 * Returns a bitmap of the latest video frame. Called on the native graphics
thread when | 285 * Returns a bitmap of the latest video frame. Called on the native graphics
thread when |
288 * DesktopView is repainted. | 286 * DesktopView is repainted. |
289 */ | 287 */ |
290 public Bitmap getVideoFrame() { | 288 public Bitmap getVideoFrame() { |
291 if (Looper.myLooper() == Looper.getMainLooper()) { | 289 if (Looper.myLooper() == Looper.getMainLooper()) { |
292 Log.w(TAG, "Canvas being redrawn on UI thread"); | 290 Log.w(TAG, "Canvas being redrawn on UI thread"); |
293 } | 291 } |
294 | 292 |
295 synchronized (mFrameLock) { | 293 synchronized (mFrameLock) { |
296 return mFrameBitmap; | 294 return mFrameBitmap; |
297 } | 295 } |
298 } | 296 } |
299 | 297 |
300 /** | 298 /** |
301 * Called by JniInterface (from native code) to set a new video frame. Calle
d on the native | 299 * Set a new video frame. Called on the native graphics thread when a new fr
ame is allocated. |
302 * graphics thread when a new frame is allocated. | |
303 */ | 300 */ |
| 301 @CalledByNative |
304 void setVideoFrame(Bitmap bitmap) { | 302 void setVideoFrame(Bitmap bitmap) { |
305 if (Looper.myLooper() == Looper.getMainLooper()) { | 303 if (Looper.myLooper() == Looper.getMainLooper()) { |
306 Log.w(TAG, "Video frame updated on UI thread"); | 304 Log.w(TAG, "Video frame updated on UI thread"); |
307 } | 305 } |
308 | 306 |
309 synchronized (mFrameLock) { | 307 synchronized (mFrameLock) { |
310 mFrameBitmap = bitmap; | 308 mFrameBitmap = bitmap; |
311 } | 309 } |
312 } | 310 } |
313 | 311 |
314 /** | 312 /** |
315 * Creates a new Bitmap to hold video frame pixels. Called by JniInterface (
from native code), | 313 * Creates a new Bitmap to hold video frame pixels. The returned Bitmap is r
eferenced by native |
316 * and the returned Bitmap is referenced by native code which writes the dec
oded frame pixels | 314 * code which writes the decoded frame pixels to it. |
317 * to it. | |
318 */ | 315 */ |
| 316 @CalledByNative |
319 static Bitmap newBitmap(int width, int height) { | 317 static Bitmap newBitmap(int width, int height) { |
320 return Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); | 318 return Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); |
321 } | 319 } |
322 | 320 |
323 /** | 321 /** |
324 * Called by JniInterface (from native code) to update the cursor shape. Thi
s is called on the | 322 * Updates the cursor shape. This is called on the graphics thread when rece
iving a new cursor |
325 * graphics thread when receiving a new cursor shape from the host. | 323 * shape from the host. |
326 */ | 324 */ |
327 void updateCursorShape( | 325 @CalledByNative |
328 int width, int height, int hotspotX, int hotspotY, ByteBuffer buffer
) { | 326 void updateCursorShape(int width, int height, int hotspotX, int hotspotY, By
teBuffer buffer) { |
329 mCursorHotspot = new Point(hotspotX, hotspotY); | 327 mCursorHotspot = new Point(hotspotX, hotspotY); |
330 | 328 |
331 int[] data = new int[width * height]; | 329 int[] data = new int[width * height]; |
332 buffer.order(ByteOrder.LITTLE_ENDIAN); | 330 buffer.order(ByteOrder.LITTLE_ENDIAN); |
333 buffer.asIntBuffer().get(data, 0, data.length); | 331 buffer.asIntBuffer().get(data, 0, data.length); |
334 mCursorBitmap = Bitmap.createBitmap(data, width, height, Bitmap.Config.A
RGB_8888); | 332 mCursorBitmap = Bitmap.createBitmap(data, width, height, Bitmap.Config.A
RGB_8888); |
335 } | 333 } |
336 | 334 |
337 /** Position of cursor hotspot within cursor image. Called on the graphics t
hread. */ | 335 /** Position of cursor hotspot within cursor image. Called on the graphics t
hread. */ |
338 public Point getCursorHotspot() { | 336 public Point getCursorHotspot() { |
339 return mCursorHotspot; | 337 return mCursorHotspot; |
340 } | 338 } |
341 | 339 |
342 /** Returns the current cursor shape. Called on the graphics thread. */ | 340 /** Returns the current cursor shape. Called on the graphics thread. */ |
343 public Bitmap getCursorBitmap() { | 341 public Bitmap getCursorBitmap() { |
344 return mCursorBitmap; | 342 return mCursorBitmap; |
345 } | 343 } |
346 | 344 |
347 // | 345 // |
348 // Third Party Authentication | 346 // Third Party Authentication |
349 // | 347 // |
350 | 348 |
351 /** | 349 /** |
352 * Called by JniInterface (from native code), to pop up a third party login
page to fetch the | 350 * Pops up a third party login page to fetch the token required for authenti
cation. |
353 * token required for authentication. | |
354 */ | 351 */ |
| 352 @CalledByNative |
355 void fetchThirdPartyToken(String tokenUrl, String clientId, String scope) { | 353 void fetchThirdPartyToken(String tokenUrl, String clientId, String scope) { |
356 mAuthenticator.fetchThirdPartyToken(tokenUrl, clientId, scope); | 354 mAuthenticator.fetchThirdPartyToken(tokenUrl, clientId, scope); |
357 } | 355 } |
358 | 356 |
359 /** | 357 /** |
360 * Called by the SessionAuthenticator to pass the |token| and |sharedSecret|
to native code to | 358 * Called by the SessionAuthenticator to pass the |token| and |sharedSecret|
to native code to |
361 * continue authentication. | 359 * continue authentication. |
362 */ | 360 */ |
363 public void onThirdPartyTokenFetched(String token, String sharedSecret) { | 361 public void onThirdPartyTokenFetched(String token, String sharedSecret) { |
364 if (!mConnected) { | 362 if (!mConnected) { |
365 return; | 363 return; |
366 } | 364 } |
367 | 365 |
368 JniInterface.nativeOnThirdPartyTokenFetched(token, sharedSecret); | 366 nativeOnThirdPartyTokenFetched(mNativeJniClient, token, sharedSecret); |
369 } | 367 } |
370 | 368 |
371 // | 369 // |
372 // Host and Client Capabilities | 370 // Host and Client Capabilities |
373 // | 371 // |
374 | 372 |
375 /** | 373 /** |
376 * Called by JniInterface (from native code) to set the list of negotiated c
apabilities between | 374 * Sets the list of negotiated capabilities between host and client. Called
on the UI thread. |
377 * host and client. Called on the UI thread. | |
378 */ | 375 */ |
| 376 @CalledByNative |
379 void setCapabilities(String capabilities) { | 377 void setCapabilities(String capabilities) { |
380 mCapabilityManager.setNegotiatedCapabilities(capabilities); | 378 mCapabilityManager.setNegotiatedCapabilities(capabilities); |
381 } | 379 } |
382 | 380 |
383 // | 381 // |
384 // Extension Message Handling | 382 // Extension Message Handling |
385 // | 383 // |
386 | 384 |
387 /** | 385 /** |
388 * Called by JniInterface (from native code), to pass on the deconstructed E
xtensionMessage to | 386 * Passes on the deconstructed ExtensionMessage to the app. Called on the UI
thread. |
389 * the app. Called on the UI thread. | |
390 */ | 387 */ |
| 388 @CalledByNative |
391 void handleExtensionMessage(String type, String data) { | 389 void handleExtensionMessage(String type, String data) { |
392 mCapabilityManager.onExtensionMessage(type, data); | 390 mCapabilityManager.onExtensionMessage(type, data); |
393 } | 391 } |
394 | 392 |
395 /** Sends an extension message to the Chromoting host. Called on the UI thre
ad. */ | 393 /** Sends an extension message to the Chromoting host. Called on the UI thre
ad. */ |
396 public void sendExtensionMessage(String type, String data) { | 394 public void sendExtensionMessage(String type, String data) { |
397 if (!mConnected) { | 395 if (!mConnected) { |
398 return; | 396 return; |
399 } | 397 } |
400 | 398 |
401 JniInterface.nativeSendExtensionMessage(type, data); | 399 nativeSendExtensionMessage(mNativeJniClient, type, data); |
402 } | 400 } |
| 401 |
| 402 private native long nativeInit(); |
| 403 |
| 404 private native void nativeDestroy(long nativeJniClient); |
| 405 |
| 406 /** Performs the native portion of the connection. */ |
| 407 private native void nativeConnect(long nativeJniClient, String username, Str
ing authToken, |
| 408 String hostJid, String hostId, String hostPubkey, String pairId, Str
ing pairSecret, |
| 409 String capabilities, String flags); |
| 410 |
| 411 /** Native implementation of Client.handleAuthenticationResponse(). */ |
| 412 private native void nativeAuthenticationResponse( |
| 413 long nativeJniClient, String pin, boolean createPair, String deviceN
ame); |
| 414 |
| 415 /** Performs the native portion of the cleanup. */ |
| 416 private native void nativeDisconnect(long nativeJniClient); |
| 417 |
| 418 /** Schedules a redraw on the native graphics thread. */ |
| 419 private native void nativeScheduleRedraw(long nativeJniClient); |
| 420 |
| 421 /** Passes authentication data to the native handling code. */ |
| 422 private native void nativeOnThirdPartyTokenFetched( |
| 423 long nativeJniClient, String token, String sharedSecret); |
| 424 |
| 425 /** Passes mouse information to the native handling code. */ |
| 426 private native void nativeSendMouseEvent( |
| 427 long nativeJniClient, int x, int y, int whichButton, boolean buttonD
own); |
| 428 |
| 429 /** Passes mouse-wheel information to the native handling code. */ |
| 430 private native void nativeSendMouseWheelEvent(long nativeJniClient, int delt
aX, int deltaY); |
| 431 |
| 432 /** Passes key press information to the native handling code. */ |
| 433 private native boolean nativeSendKeyEvent( |
| 434 long nativeJniClient, int scanCode, int keyCode, boolean keyDown); |
| 435 |
| 436 /** Passes text event information to the native handling code. */ |
| 437 private native void nativeSendTextEvent(long nativeJniClient, String text); |
| 438 |
| 439 /** Passes touch event information to the native handling code. */ |
| 440 private native void nativeSendTouchEvent( |
| 441 long nativeJniClient, int eventType, TouchEventData[] data); |
| 442 |
| 443 /** Native implementation of Client.enableVideoChannel() */ |
| 444 private native void nativeEnableVideoChannel(long nativeJniClient, boolean e
nable); |
| 445 |
| 446 /** Passes extension message to the native code. */ |
| 447 private native void nativeSendExtensionMessage(long nativeJniClient, String
type, String data); |
403 } | 448 } |
OLD | NEW |