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