Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(499)

Side by Side Diff: remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java

Issue 451973002: Capabilities + Extensions + Cast Host Extension Support for Android client (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: FindBugs Pass + Changes after Review Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chromoting.jni; 5 package org.chromium.chromoting.jni;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.app.AlertDialog; 8 import android.app.AlertDialog;
9 import android.content.Context; 9 import android.content.Context;
10 import android.content.DialogInterface; 10 import android.content.DialogInterface;
11 import android.content.SharedPreferences; 11 import android.content.SharedPreferences;
12 import android.graphics.Bitmap; 12 import android.graphics.Bitmap;
13 import android.graphics.Point; 13 import android.graphics.Point;
14 import android.os.Build; 14 import android.os.Build;
15 import android.os.Looper; 15 import android.os.Looper;
16 import android.util.Log; 16 import android.util.Log;
17 import android.view.KeyEvent; 17 import android.view.KeyEvent;
18 import android.view.View; 18 import android.view.View;
19 import android.widget.CheckBox; 19 import android.widget.CheckBox;
20 import android.widget.TextView; 20 import android.widget.TextView;
21 import android.widget.Toast; 21 import android.widget.Toast;
22 22
23 import org.chromium.base.CalledByNative; 23 import org.chromium.base.CalledByNative;
24 import org.chromium.base.JNINamespace; 24 import org.chromium.base.JNINamespace;
25 import org.chromium.chromoting.CapabilityManager;
25 import org.chromium.chromoting.Chromoting; 26 import org.chromium.chromoting.Chromoting;
26 import org.chromium.chromoting.R; 27 import org.chromium.chromoting.R;
27 28
28 import java.nio.ByteBuffer; 29 import java.nio.ByteBuffer;
29 import java.nio.ByteOrder; 30 import java.nio.ByteOrder;
30 31
31 /** 32 /**
32 * Initializes the Chromium remoting library, and provides JNI calls into it. 33 * Initializes the Chromium remoting library, and provides JNI calls into it.
33 * All interaction with the native code is centralized in this class. 34 * All interaction with the native code is centralized in this class.
34 */ 35 */
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 137
137 /** Protects access to sFrameBitmap. */ 138 /** Protects access to sFrameBitmap. */
138 private static final Object sFrameLock = new Object(); 139 private static final Object sFrameLock = new Object();
139 140
140 /** Position of cursor hot-spot. Accessed on the graphics thread. */ 141 /** Position of cursor hot-spot. Accessed on the graphics thread. */
141 private static Point sCursorHotspot = new Point(); 142 private static Point sCursorHotspot = new Point();
142 143
143 /** Bitmap holding the cursor shape. Accessed on the graphics thread. */ 144 /** Bitmap holding the cursor shape. Accessed on the graphics thread. */
144 private static Bitmap sCursorBitmap = null; 145 private static Bitmap sCursorBitmap = null;
145 146
147 /** Capability Manager through which capabilities and extensions are handled . */
148 private static CapabilityManager sCapabilityManager = CapabilityManager.getI nstance();
149
146 /** 150 /**
147 * To be called once from the main Activity. Any subsequent calls will updat e the application 151 * To be called once from the main Activity. Any subsequent calls will updat e the application
148 * context, but not reload the library. This is useful e.g. when the activit y is closed and the 152 * context, but not reload the library. This is useful e.g. when the activit y is closed and the
149 * user later wants to return to the application. Called on the UI thread. 153 * user later wants to return to the application. Called on the UI thread.
150 */ 154 */
151 public static void loadLibrary(Activity context) { 155 public static void loadLibrary(Activity context) {
152 sContext = context; 156 sContext = context;
153 157
154 if (sLoaded) return; 158 if (sLoaded) return;
155 159
(...skipping 14 matching lines...) Expand all
170 public static native String nativeGetClientSecret(); 174 public static native String nativeGetClientSecret();
171 175
172 /** Attempts to form a connection to the user-selected host. Called on the U I thread. */ 176 /** Attempts to form a connection to the user-selected host. Called on the U I thread. */
173 public static void connectToHost(String username, String authToken, 177 public static void connectToHost(String username, String authToken,
174 String hostJid, String hostId, String hostPubkey, ConnectionListener listener) { 178 String hostJid, String hostId, String hostPubkey, ConnectionListener listener) {
175 disconnectFromHost(); 179 disconnectFromHost();
176 180
177 sConnectionListener = listener; 181 sConnectionListener = listener;
178 SharedPreferences prefs = sContext.getPreferences(Activity.MODE_PRIVATE) ; 182 SharedPreferences prefs = sContext.getPreferences(Activity.MODE_PRIVATE) ;
179 nativeConnect(username, authToken, hostJid, hostId, hostPubkey, 183 nativeConnect(username, authToken, hostJid, hostId, hostPubkey,
180 prefs.getString(hostId + "_id", ""), prefs.getString(hostId + "_ secret", "")); 184 prefs.getString(hostId + "_id", ""), prefs.getString(hostId + "_secr et", ""),
Lambros 2014/08/14 23:54:25 nit: 8-space indent
aiguha 2014/08/15 03:37:30 Done.
185 sCapabilityManager.getLocalCapabilities());
181 sConnected = true; 186 sConnected = true;
182 } 187 }
183 188
184 /** Performs the native portion of the connection. */ 189 /** Performs the native portion of the connection. */
185 private static native void nativeConnect(String username, String authToken, String hostJid, 190 private static native void nativeConnect(
186 String hostId, String hostPubkey, String pairId, String pairSecret); 191 String username, String authToken, String hostJid, String hostId, String hostPubkey,
Lambros 2014/08/14 23:54:25 nit: 8-space indent. Also you can begin the parame
aiguha 2014/08/15 03:37:30 Done.
192 String pairId, String pairSecret, String capabilities);
187 193
188 /** Severs the connection and cleans up. Called on the UI thread. */ 194 /** Severs the connection and cleans up. Called on the UI thread. */
189 public static void disconnectFromHost() { 195 public static void disconnectFromHost() {
190 if (!sConnected) { 196 if (!sConnected) {
191 return; 197 return;
192 } 198 }
193 199
194 sConnectionListener.onConnectionState(ConnectionListener.State.CLOSED, 200 sConnectionListener.onConnectionState(ConnectionListener.State.CLOSED,
195 ConnectionListener.Error.OK); 201 ConnectionListener.Error.OK);
196 202
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 public static void onThirdPartyTokenFetched(String token, String sharedSecre t) { 489 public static void onThirdPartyTokenFetched(String token, String sharedSecre t) {
484 if (!sConnected) { 490 if (!sConnected) {
485 return; 491 return;
486 } 492 }
487 493
488 nativeOnThirdPartyTokenFetched(token, sharedSecret); 494 nativeOnThirdPartyTokenFetched(token, sharedSecret);
489 } 495 }
490 496
491 /** Passes authentication data to the native handling code. */ 497 /** Passes authentication data to the native handling code. */
492 private static native void nativeOnThirdPartyTokenFetched(String token, Stri ng sharedSecret); 498 private static native void nativeOnThirdPartyTokenFetched(String token, Stri ng sharedSecret);
499
500 //
501 // Host and Client Capabilities
502 //
503
504 /** Set the list of negotiated capabilities between host and client. Called on the UI thread. */
505 @CalledByNative
506 public static void setCapabilities(String capabilities) {
507 sCapabilityManager.setNegotiatedCapabilities(capabilities);
508 }
509
510 //
511 // Extension Message Handling
512 //
513
514 /** Passes on the deconstructed ExtensionMessage to the app. Called on the U I thread. */
515 @CalledByNative
516 public static void handleExtensionMessage(String type, String data) {
517 sCapabilityManager.onExtensionMessage(type, data);
518 }
519
Lambros 2014/08/14 23:54:25 nit: only one blank line
aiguha 2014/08/15 03:37:30 Done.
520
521 public static void sendExtensionMessage(String type, String data) {
Lambros 2014/08/14 23:54:25 Add some JavaDoc. And say which thread this should
aiguha 2014/08/15 03:37:30 Done.
522 if (!sConnected)
Lambros 2014/08/14 23:54:25 nit: Add braces, consistent with above.
aiguha 2014/08/15 03:37:30 Done.
523 return;
524
525 nativeSendExtensionMessage(type, data);
526 }
527
528 private static native void nativeSendExtensionMessage(String type, String da ta);
493 } 529 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698