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