Chromium Code Reviews| 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 by native code whenever the connection status changes. Called on the UI thread. */ |
|
Lambros
2016/05/25 20:51:49
The CalledByNative annotation means you can remove
Yuwei
2016/05/25 21:19:53
Done.
| |
| 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 by JniInterface (from native code) to prompt the user to enter a P IN. Called on the |
| 167 * UI thread. | 165 * UI thread. |
| 168 */ | 166 */ |
| 167 @CalledByNative | |
|
Lambros
2016/05/25 20:51:50
No longer called by JniInterface. Comment can be s
Yuwei
2016/05/25 21:19:52
Done.
| |
| 169 void displayAuthenticationPrompt(boolean pairingSupported) { | 168 void displayAuthenticationPrompt(boolean pairingSupported) { |
| 170 mAuthenticator.displayAuthenticationPrompt(pairingSupported); | 169 mAuthenticator.displayAuthenticationPrompt(pairingSupported); |
| 171 } | 170 } |
| 172 | 171 |
| 173 /** | 172 /** |
| 174 * Called by the SessionAuthenticator after the user enters a PIN. | 173 * Called by the SessionAuthenticator after the user enters a PIN. |
| 175 * @param pin The entered PIN. | 174 * @param pin The entered PIN. |
| 176 * @param createPair Whether to create a new pairing for this client. | 175 * @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 | 176 * @param deviceName The device name to appear in the pairing registry. Only used if createPair |
| 178 * is true. | 177 * is true. |
| 179 */ | 178 */ |
| 180 public void handleAuthenticationResponse( | 179 public void handleAuthenticationResponse( |
| 181 String pin, boolean createPair, String deviceName) { | 180 String pin, boolean createPair, String deviceName) { |
| 182 assert mConnected; | 181 assert mConnected; |
| 183 JniInterface.nativeAuthenticationResponse(pin, createPair, deviceName); | 182 nativeAuthenticationResponse(mNativeJniClient, pin, createPair, deviceNa me); |
| 184 } | 183 } |
| 185 | 184 |
| 186 /** | 185 /** |
| 187 * Called by JniInterface (from native code), to save newly-received pairing credentials to | 186 * Called by JniInterface (from native code), to save newly-received pairing credentials to |
| 188 * permanent storage. Called on the UI thread. | 187 * permanent storage. Called on the UI thread. |
| 189 */ | 188 */ |
| 189 @CalledByNative | |
|
Lambros
2016/05/25 20:51:50
Saves newly-received ...
Yuwei
2016/05/25 21:19:52
Done.
| |
| 190 void commitPairingCredentials(String host, String id, String secret) { | 190 void commitPairingCredentials(String host, String id, String secret) { |
| 191 mAuthenticator.commitPairingCredentials(host, id, secret); | 191 mAuthenticator.commitPairingCredentials(host, id, secret); |
| 192 } | 192 } |
| 193 | 193 |
| 194 /** | 194 /** |
| 195 * 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 |
| 196 * on the UI thread. | 196 * on the UI thread. |
| 197 */ | 197 */ |
| 198 public void sendMouseEvent(int x, int y, int whichButton, boolean buttonDown ) { | 198 public void sendMouseEvent(int x, int y, int whichButton, boolean buttonDown ) { |
| 199 if (!mConnected) { | 199 if (!mConnected) { |
| 200 return; | 200 return; |
| 201 } | 201 } |
| 202 | 202 |
| 203 JniInterface.nativeSendMouseEvent(x, y, whichButton, buttonDown); | 203 nativeSendMouseEvent(mNativeJniClient, x, y, whichButton, buttonDown); |
| 204 } | 204 } |
| 205 | 205 |
| 206 /** 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. */ |
| 207 public void sendMouseWheelEvent(int deltaX, int deltaY) { | 207 public void sendMouseWheelEvent(int deltaX, int deltaY) { |
| 208 if (!mConnected) { | 208 if (!mConnected) { |
| 209 return; | 209 return; |
| 210 } | 210 } |
| 211 | 211 |
| 212 JniInterface.nativeSendMouseWheelEvent(deltaX, deltaY); | 212 nativeSendMouseWheelEvent(mNativeJniClient, deltaX, deltaY); |
| 213 } | 213 } |
| 214 | 214 |
| 215 /** | 215 /** |
| 216 * 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 |
| 217 * keyCode is ignored. | 217 * keyCode is ignored. |
| 218 */ | 218 */ |
| 219 public boolean sendKeyEvent(int scanCode, int keyCode, boolean keyDown) { | 219 public boolean sendKeyEvent(int scanCode, int keyCode, boolean keyDown) { |
| 220 if (!mConnected) { | 220 if (!mConnected) { |
| 221 return false; | 221 return false; |
| 222 } | 222 } |
| 223 | 223 |
| 224 return JniInterface.nativeSendKeyEvent(scanCode, keyCode, keyDown); | 224 return nativeSendKeyEvent(mNativeJniClient, scanCode, keyCode, keyDown); |
| 225 } | 225 } |
| 226 | 226 |
| 227 /** Sends TextEvent to the host. Called on the UI thread. */ | 227 /** Sends TextEvent to the host. Called on the UI thread. */ |
| 228 public void sendTextEvent(String text) { | 228 public void sendTextEvent(String text) { |
| 229 if (!mConnected) { | 229 if (!mConnected) { |
| 230 return; | 230 return; |
| 231 } | 231 } |
| 232 | 232 |
| 233 JniInterface.nativeSendTextEvent(text); | 233 nativeSendTextEvent(mNativeJniClient, text); |
| 234 } | 234 } |
| 235 | 235 |
| 236 /** 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. */ |
| 237 public void sendTouchEvent(TouchEventData.EventType eventType, TouchEventDat a[] data) { | 237 public void sendTouchEvent(TouchEventData.EventType eventType, TouchEventDat a[] data) { |
| 238 if (!mConnected) { | 238 if (!mConnected) { |
| 239 return; | 239 return; |
| 240 } | 240 } |
| 241 | 241 |
| 242 JniInterface.nativeSendTouchEvent(eventType.value(), data); | 242 nativeSendTouchEvent(mNativeJniClient, eventType.value(), data); |
| 243 } | 243 } |
| 244 | 244 |
| 245 /** | 245 /** |
| 246 * 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 |
| 247 * lifecycle events. | 247 * lifecycle events. |
| 248 */ | 248 */ |
| 249 public void enableVideoChannel(boolean enable) { | 249 public void enableVideoChannel(boolean enable) { |
| 250 if (!mConnected) { | 250 if (!mConnected) { |
| 251 return; | 251 return; |
| 252 } | 252 } |
| 253 | 253 |
| 254 JniInterface.nativeEnableVideoChannel(enable); | 254 nativeEnableVideoChannel(mNativeJniClient, enable); |
| 255 } | 255 } |
| 256 | 256 |
| 257 /** | 257 /** |
| 258 * 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 |
| 259 * 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 |
| 260 * thread. | 260 * thread. |
| 261 */ | 261 */ |
| 262 public void provideRedrawCallback(Runnable redrawCallback) { | 262 public void provideRedrawCallback(Runnable redrawCallback) { |
| 263 mRedrawCallback = redrawCallback; | 263 mRedrawCallback = redrawCallback; |
| 264 } | 264 } |
| 265 | 265 |
| 266 /** 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. */ |
| 267 public boolean redrawGraphics() { | 267 public boolean redrawGraphics() { |
| 268 if (!mConnected || mRedrawCallback == null) return false; | 268 if (!mConnected || mRedrawCallback == null) return false; |
| 269 | 269 |
| 270 JniInterface.nativeScheduleRedraw(); | 270 nativeScheduleRedraw(mNativeJniClient); |
| 271 return true; | 271 return true; |
| 272 } | 272 } |
| 273 | 273 |
| 274 /** | 274 /** |
| 275 * Called by JniInterface to perform the redrawing callback requested by | 275 * Called by JniInterface to perform the redrawing callback requested by |
|
Lambros
2016/05/25 20:51:50
Performs the redrawing callback ...
Yuwei
2016/05/25 21:19:53
Done.
| |
| 276 * {@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. | 277 * Called on the graphics thread. |
| 278 */ | 278 */ |
| 279 @CalledByNative | |
| 279 void redrawGraphicsInternal() { | 280 void redrawGraphicsInternal() { |
| 280 Runnable callback = mRedrawCallback; | 281 Runnable callback = mRedrawCallback; |
| 281 if (callback != null) { | 282 if (callback != null) { |
| 282 callback.run(); | 283 callback.run(); |
| 283 } | 284 } |
| 284 } | 285 } |
| 285 | 286 |
| 286 /** | 287 /** |
| 287 * Returns a bitmap of the latest video frame. Called on the native graphics thread when | 288 * Returns a bitmap of the latest video frame. Called on the native graphics thread when |
| 288 * DesktopView is repainted. | 289 * DesktopView is repainted. |
| 289 */ | 290 */ |
| 290 public Bitmap getVideoFrame() { | 291 public Bitmap getVideoFrame() { |
| 291 if (Looper.myLooper() == Looper.getMainLooper()) { | 292 if (Looper.myLooper() == Looper.getMainLooper()) { |
| 292 Log.w(TAG, "Canvas being redrawn on UI thread"); | 293 Log.w(TAG, "Canvas being redrawn on UI thread"); |
| 293 } | 294 } |
| 294 | 295 |
| 295 synchronized (mFrameLock) { | 296 synchronized (mFrameLock) { |
| 296 return mFrameBitmap; | 297 return mFrameBitmap; |
| 297 } | 298 } |
| 298 } | 299 } |
| 299 | 300 |
| 300 /** | 301 /** |
| 301 * Called by JniInterface (from native code) to set a new video frame. Calle d on the native | 302 * 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. | 303 * graphics thread when a new frame is allocated. |
| 303 */ | 304 */ |
| 305 @CalledByNative | |
|
Lambros
2016/05/25 20:51:49
Sets a new video frame. ...
Yuwei
2016/05/25 21:19:52
Done.
| |
| 304 void setVideoFrame(Bitmap bitmap) { | 306 void setVideoFrame(Bitmap bitmap) { |
| 305 if (Looper.myLooper() == Looper.getMainLooper()) { | 307 if (Looper.myLooper() == Looper.getMainLooper()) { |
| 306 Log.w(TAG, "Video frame updated on UI thread"); | 308 Log.w(TAG, "Video frame updated on UI thread"); |
| 307 } | 309 } |
| 308 | 310 |
| 309 synchronized (mFrameLock) { | 311 synchronized (mFrameLock) { |
| 310 mFrameBitmap = bitmap; | 312 mFrameBitmap = bitmap; |
| 311 } | 313 } |
| 312 } | 314 } |
| 313 | 315 |
| 314 /** | 316 /** |
| 315 * Creates a new Bitmap to hold video frame pixels. Called by JniInterface ( from native code), | 317 * Creates a new Bitmap to hold video frame pixels. Called by JniInterface ( from native code), |
| 316 * and the returned Bitmap is referenced by native code which writes the dec oded frame pixels | 318 * and the returned Bitmap is referenced by native code which writes the dec oded frame pixels |
|
Lambros
2016/05/25 20:51:49
Remove "Called by JniInterface (from native code)"
Yuwei
2016/05/25 21:19:52
Done.
| |
| 317 * to it. | 319 * to it. |
| 318 */ | 320 */ |
| 321 @CalledByNative | |
| 319 static Bitmap newBitmap(int width, int height) { | 322 static Bitmap newBitmap(int width, int height) { |
| 320 return Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); | 323 return Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); |
| 321 } | 324 } |
| 322 | 325 |
| 323 /** | 326 /** |
| 324 * Called by JniInterface (from native code) to update the cursor shape. Thi s is called on the | 327 * Called by JniInterface (from native code) to update the cursor shape. Thi s is called on the |
|
Lambros
2016/05/25 20:51:50
Updates the cursor shape.
Yuwei
2016/05/25 21:19:52
Done.
| |
| 325 * graphics thread when receiving a new cursor shape from the host. | 328 * graphics thread when receiving a new cursor shape from the host. |
| 326 */ | 329 */ |
| 327 void updateCursorShape( | 330 @CalledByNative |
| 328 int width, int height, int hotspotX, int hotspotY, ByteBuffer buffer ) { | 331 void updateCursorShape(int width, int height, int hotspotX, int hotspotY, By teBuffer buffer) { |
| 329 mCursorHotspot = new Point(hotspotX, hotspotY); | 332 mCursorHotspot = new Point(hotspotX, hotspotY); |
| 330 | 333 |
| 331 int[] data = new int[width * height]; | 334 int[] data = new int[width * height]; |
| 332 buffer.order(ByteOrder.LITTLE_ENDIAN); | 335 buffer.order(ByteOrder.LITTLE_ENDIAN); |
| 333 buffer.asIntBuffer().get(data, 0, data.length); | 336 buffer.asIntBuffer().get(data, 0, data.length); |
| 334 mCursorBitmap = Bitmap.createBitmap(data, width, height, Bitmap.Config.A RGB_8888); | 337 mCursorBitmap = Bitmap.createBitmap(data, width, height, Bitmap.Config.A RGB_8888); |
| 335 } | 338 } |
| 336 | 339 |
| 337 /** Position of cursor hotspot within cursor image. Called on the graphics t hread. */ | 340 /** Position of cursor hotspot within cursor image. Called on the graphics t hread. */ |
| 338 public Point getCursorHotspot() { | 341 public Point getCursorHotspot() { |
| 339 return mCursorHotspot; | 342 return mCursorHotspot; |
| 340 } | 343 } |
| 341 | 344 |
| 342 /** Returns the current cursor shape. Called on the graphics thread. */ | 345 /** Returns the current cursor shape. Called on the graphics thread. */ |
| 343 public Bitmap getCursorBitmap() { | 346 public Bitmap getCursorBitmap() { |
| 344 return mCursorBitmap; | 347 return mCursorBitmap; |
| 345 } | 348 } |
| 346 | 349 |
| 347 // | 350 // |
| 348 // Third Party Authentication | 351 // Third Party Authentication |
| 349 // | 352 // |
| 350 | 353 |
| 351 /** | 354 /** |
| 352 * Called by JniInterface (from native code), to pop up a third party login page to fetch the | 355 * Called by JniInterface (from native code), to pop up a third party login page to fetch the |
|
Lambros
2016/05/25 20:51:49
Pops up a third party ...
Yuwei
2016/05/25 21:19:52
Done.
| |
| 353 * token required for authentication. | 356 * token required for authentication. |
| 354 */ | 357 */ |
| 358 @CalledByNative | |
| 355 void fetchThirdPartyToken(String tokenUrl, String clientId, String scope) { | 359 void fetchThirdPartyToken(String tokenUrl, String clientId, String scope) { |
| 356 mAuthenticator.fetchThirdPartyToken(tokenUrl, clientId, scope); | 360 mAuthenticator.fetchThirdPartyToken(tokenUrl, clientId, scope); |
| 357 } | 361 } |
| 358 | 362 |
| 359 /** | 363 /** |
| 360 * Called by the SessionAuthenticator to pass the |token| and |sharedSecret| to native code to | 364 * Called by the SessionAuthenticator to pass the |token| and |sharedSecret| to native code to |
| 361 * continue authentication. | 365 * continue authentication. |
| 362 */ | 366 */ |
| 363 public void onThirdPartyTokenFetched(String token, String sharedSecret) { | 367 public void onThirdPartyTokenFetched(String token, String sharedSecret) { |
| 364 if (!mConnected) { | 368 if (!mConnected) { |
| 365 return; | 369 return; |
| 366 } | 370 } |
| 367 | 371 |
| 368 JniInterface.nativeOnThirdPartyTokenFetched(token, sharedSecret); | 372 nativeOnThirdPartyTokenFetched(mNativeJniClient, token, sharedSecret); |
| 369 } | 373 } |
| 370 | 374 |
| 371 // | 375 // |
| 372 // Host and Client Capabilities | 376 // Host and Client Capabilities |
| 373 // | 377 // |
| 374 | 378 |
| 375 /** | 379 /** |
| 376 * Called by JniInterface (from native code) to set the list of negotiated c apabilities between | 380 * Called by JniInterface (from native code) to set the list of negotiated c apabilities between |
|
Lambros
2016/05/25 20:51:50
Sets the list...
Yuwei
2016/05/25 21:19:53
Done.
| |
| 377 * host and client. Called on the UI thread. | 381 * host and client. Called on the UI thread. |
| 378 */ | 382 */ |
| 383 @CalledByNative | |
| 379 void setCapabilities(String capabilities) { | 384 void setCapabilities(String capabilities) { |
| 380 mCapabilityManager.setNegotiatedCapabilities(capabilities); | 385 mCapabilityManager.setNegotiatedCapabilities(capabilities); |
| 381 } | 386 } |
| 382 | 387 |
| 383 // | 388 // |
| 384 // Extension Message Handling | 389 // Extension Message Handling |
| 385 // | 390 // |
| 386 | 391 |
| 387 /** | 392 /** |
| 388 * Called by JniInterface (from native code), to pass on the deconstructed E xtensionMessage to | 393 * Called by JniInterface (from native code), to pass on the deconstructed E xtensionMessage to |
|
Lambros
2016/05/25 20:51:50
Passes on the ...
Yuwei
2016/05/25 21:19:53
Done.
| |
| 389 * the app. Called on the UI thread. | 394 * the app. Called on the UI thread. |
| 390 */ | 395 */ |
| 396 @CalledByNative | |
| 391 void handleExtensionMessage(String type, String data) { | 397 void handleExtensionMessage(String type, String data) { |
| 392 mCapabilityManager.onExtensionMessage(type, data); | 398 mCapabilityManager.onExtensionMessage(type, data); |
| 393 } | 399 } |
| 394 | 400 |
| 395 /** Sends an extension message to the Chromoting host. Called on the UI thre ad. */ | 401 /** Sends an extension message to the Chromoting host. Called on the UI thre ad. */ |
| 396 public void sendExtensionMessage(String type, String data) { | 402 public void sendExtensionMessage(String type, String data) { |
| 397 if (!mConnected) { | 403 if (!mConnected) { |
| 398 return; | 404 return; |
| 399 } | 405 } |
| 400 | 406 |
| 401 JniInterface.nativeSendExtensionMessage(type, data); | 407 nativeSendExtensionMessage(mNativeJniClient, type, data); |
| 402 } | 408 } |
| 409 | |
| 410 // JNI Interface. | |
|
Lambros
2016/05/25 20:51:49
Remove this comment.
Yuwei
2016/05/25 21:19:52
Done.
| |
| 411 | |
| 412 private native long nativeInit(); | |
|
Lambros
2016/05/25 20:51:49
OK to group these native.. methods together, as lo
Yuwei
2016/05/25 21:19:52
Since it is just moving one line of code (i.e. pri
| |
| 413 | |
| 414 private native void nativeDestroy(long nativeJniClient); | |
| 415 | |
| 416 /** Performs the native portion of the connection. */ | |
| 417 private native void nativeConnect(long nativeJniClient, String username, Str ing authToken, | |
| 418 String hostJid, String hostId, String hostPubkey, String pairId, Str ing pairSecret, | |
| 419 String capabilities, String flags); | |
| 420 | |
| 421 /** Native implementation of Client.handleAuthenticationResponse(). */ | |
| 422 private native void nativeAuthenticationResponse( | |
| 423 long nativeJniClient, String pin, boolean createPair, String deviceN ame); | |
| 424 | |
| 425 /** Performs the native portion of the cleanup. */ | |
| 426 private native void nativeDisconnect(long nativeJniClient); | |
| 427 | |
| 428 /** Schedules a redraw on the native graphics thread. */ | |
| 429 private native void nativeScheduleRedraw(long nativeJniClient); | |
| 430 | |
| 431 /** Passes authentication data to the native handling code. */ | |
| 432 private native void nativeOnThirdPartyTokenFetched( | |
| 433 long nativeJniClient, String token, String sharedSecret); | |
| 434 | |
| 435 /** Passes mouse information to the native handling code. */ | |
| 436 private native void nativeSendMouseEvent( | |
| 437 long nativeJniClient, int x, int y, int whichButton, boolean buttonD own); | |
| 438 | |
| 439 /** Passes mouse-wheel information to the native handling code. */ | |
| 440 private native void nativeSendMouseWheelEvent(long nativeJniClient, int delt aX, int deltaY); | |
| 441 | |
| 442 /** Passes key press information to the native handling code. */ | |
| 443 private native boolean nativeSendKeyEvent( | |
| 444 long nativeJniClient, int scanCode, int keyCode, boolean keyDown); | |
| 445 | |
| 446 /** Passes text event information to the native handling code. */ | |
| 447 private native void nativeSendTextEvent(long nativeJniClient, String text); | |
| 448 | |
| 449 /** Passes touch event information to the native handling code. */ | |
| 450 private native void nativeSendTouchEvent( | |
| 451 long nativeJniClient, int eventType, TouchEventData[] data); | |
| 452 | |
| 453 /** Native implementation of Client.enableVideoChannel() */ | |
| 454 private native void nativeEnableVideoChannel(long nativeJniClient, boolean e nable); | |
| 455 | |
| 456 /** Passes extension message to the native code. */ | |
| 457 private native void nativeSendExtensionMessage(long nativeJniClient, String type, String data); | |
| 403 } | 458 } |
| OLD | NEW |