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

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

Issue 407403002: Chromoting: Synchronize connected/disconnected state between Java/C++ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments 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 | Annotate | Revision Log
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 22
22 import org.chromium.base.CalledByNative; 23 import org.chromium.base.CalledByNative;
23 import org.chromium.base.JNINamespace; 24 import org.chromium.base.JNINamespace;
24 import org.chromium.chromoting.Chromoting; 25 import org.chromium.chromoting.Chromoting;
25 import org.chromium.chromoting.R; 26 import org.chromium.chromoting.R;
26 27
27 import java.nio.ByteBuffer; 28 import java.nio.ByteBuffer;
28 import java.nio.ByteOrder; 29 import java.nio.ByteOrder;
29 30
30 /** 31 /**
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 prefs.getString(hostId + "_id", ""), prefs.getString(hostId + "_ secret", "")); 180 prefs.getString(hostId + "_id", ""), prefs.getString(hostId + "_ secret", ""));
180 sConnected = true; 181 sConnected = true;
181 } 182 }
182 183
183 /** Performs the native portion of the connection. */ 184 /** Performs the native portion of the connection. */
184 private static native void nativeConnect(String username, String authToken, String hostJid, 185 private static native void nativeConnect(String username, String authToken, String hostJid,
185 String hostId, String hostPubkey, String pairId, String pairSecret); 186 String hostId, String hostPubkey, String pairId, String pairSecret);
186 187
187 /** Severs the connection and cleans up. Called on the UI thread. */ 188 /** Severs the connection and cleans up. Called on the UI thread. */
188 public static void disconnectFromHost() { 189 public static void disconnectFromHost() {
189 if (!sConnected) return; 190 if (!sConnected) {
191 return;
192 }
190 193
191 sConnectionListener.onConnectionState(ConnectionListener.State.CLOSED, 194 sConnectionListener.onConnectionState(ConnectionListener.State.CLOSED,
192 ConnectionListener.Error.OK); 195 ConnectionListener.Error.OK);
193 196
197 disconnectFromHostWithoutNotification();
198 }
199
200 /** Same as disconnectFromHost() but without notifying the ConnectionListene r. */
201 private static void disconnectFromHostWithoutNotification() {
202 if (!sConnected) {
203 return;
204 }
205
194 nativeDisconnect(); 206 nativeDisconnect();
195 sConnectionListener = null; 207 sConnectionListener = null;
196 sConnected = false; 208 sConnected = false;
197 209
198 // Drop the reference to free the Bitmap for GC. 210 // Drop the reference to free the Bitmap for GC.
199 synchronized (sFrameLock) { 211 synchronized (sFrameLock) {
200 sFrameBitmap = null; 212 sFrameBitmap = null;
201 } 213 }
202 } 214 }
203 215
204 /** Performs the native portion of the cleanup. */ 216 /** Performs the native portion of the cleanup. */
205 private static native void nativeDisconnect(); 217 private static native void nativeDisconnect();
206 218
207 /** Reports whenever the connection status changes. Called on the UI thread. */ 219 /** Called by native code whenever the connection status changes. Called on the UI thread. */
208 @CalledByNative 220 @CalledByNative
209 private static void reportConnectionStatus(int state, int error) { 221 private static void onConnectionState(int stateCode, int errorCode) {
210 sConnectionListener.onConnectionState(ConnectionListener.State.fromValue (state), 222 ConnectionListener.State state = ConnectionListener.State.fromValue(stat eCode);
211 ConnectionListener.Error.fromValue(error)); 223 ConnectionListener.Error error = ConnectionListener.Error.fromValue(erro rCode);
224 sConnectionListener.onConnectionState(state, error);
225 if (state == ConnectionListener.State.FAILED || state == ConnectionListe ner.State.CLOSED) {
226 // Disconnect from the host here, otherwise the next time connectToH ost() is called,
227 // it will try to disconnect, triggering an incorrect status notific ation.
228 disconnectFromHostWithoutNotification();
229 }
212 } 230 }
213 231
214 /** Prompts the user to enter a PIN. Called on the UI thread. */ 232 /** Prompts the user to enter a PIN. Called on the UI thread. */
215 @CalledByNative 233 @CalledByNative
216 private static void displayAuthenticationPrompt(boolean pairingSupported) { 234 private static void displayAuthenticationPrompt(boolean pairingSupported) {
217 AlertDialog.Builder pinPrompt = new AlertDialog.Builder(sContext); 235 AlertDialog.Builder pinPrompt = new AlertDialog.Builder(sContext);
218 pinPrompt.setTitle(sContext.getString(R.string.title_authenticate)); 236 pinPrompt.setTitle(sContext.getString(R.string.title_authenticate));
219 pinPrompt.setMessage(sContext.getString(R.string.pin_message_android)); 237 pinPrompt.setMessage(sContext.getString(R.string.pin_message_android));
220 pinPrompt.setIcon(android.R.drawable.ic_lock_lock); 238 pinPrompt.setIcon(android.R.drawable.ic_lock_lock);
221 239
222 final View pinEntry = sContext.getLayoutInflater().inflate(R.layout.pin_ dialog, null); 240 final View pinEntry = sContext.getLayoutInflater().inflate(R.layout.pin_ dialog, null);
223 pinPrompt.setView(pinEntry); 241 pinPrompt.setView(pinEntry);
224 242
225 final TextView pinTextView = (TextView)pinEntry.findViewById(R.id.pin_di alog_text); 243 final TextView pinTextView = (TextView)pinEntry.findViewById(R.id.pin_di alog_text);
226 final CheckBox pinCheckBox = (CheckBox)pinEntry.findViewById(R.id.pin_di alog_check); 244 final CheckBox pinCheckBox = (CheckBox)pinEntry.findViewById(R.id.pin_di alog_check);
227 245
228 if (!pairingSupported) { 246 if (!pairingSupported) {
229 pinCheckBox.setChecked(false); 247 pinCheckBox.setChecked(false);
230 pinCheckBox.setVisibility(View.GONE); 248 pinCheckBox.setVisibility(View.GONE);
231 } 249 }
232 250
233 pinPrompt.setPositiveButton( 251 pinPrompt.setPositiveButton(
234 R.string.connect_button, new DialogInterface.OnClickListener() { 252 R.string.connect_button, new DialogInterface.OnClickListener() {
235 @Override 253 @Override
236 public void onClick(DialogInterface dialog, int which) { 254 public void onClick(DialogInterface dialog, int which) {
237 Log.i("jniiface", "User provided a PIN code"); 255 Log.i("jniiface", "User provided a PIN code");
238 nativeAuthenticationResponse(String.valueOf(pinTextView. getText()), 256 if (sConnected) {
239 pinCheckBox.isChecked(), Build.MODEL); 257 nativeAuthenticationResponse(String.valueOf(pinTextV iew.getText()),
258 pinCheckBox.isChecked(), Build.MODEL);
259 } else {
260 String message = sContext.getString(R.string.error_n etwork_error);
261 Toast.makeText(sContext, message, Toast.LENGTH_LONG) .show();
262 }
240 } 263 }
241 }); 264 });
242 265
243 pinPrompt.setNegativeButton( 266 pinPrompt.setNegativeButton(
244 R.string.cancel, new DialogInterface.OnClickListener() { 267 R.string.cancel, new DialogInterface.OnClickListener() {
245 @Override 268 @Override
246 public void onClick(DialogInterface dialog, int which) { 269 public void onClick(DialogInterface dialog, int which) {
247 Log.i("jniiface", "User canceled pin entry prompt"); 270 Log.i("jniiface", "User canceled pin entry prompt");
248 disconnectFromHost(); 271 disconnectFromHost();
249 } 272 }
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 /** Pops up a third party login page to fetch the token required for authent ication. */ 473 /** Pops up a third party login page to fetch the token required for authent ication. */
451 @CalledByNative 474 @CalledByNative
452 public static void fetchThirdPartyToken(String tokenUrl, String clientId, St ring scope) { 475 public static void fetchThirdPartyToken(String tokenUrl, String clientId, St ring scope) {
453 Chromoting app = (Chromoting) sContext; 476 Chromoting app = (Chromoting) sContext;
454 app.fetchThirdPartyToken(tokenUrl, clientId, scope); 477 app.fetchThirdPartyToken(tokenUrl, clientId, scope);
455 } 478 }
456 479
457 /** 480 /**
458 * Notify the native code to continue authentication with the |token| and th e |sharedSecret|. 481 * Notify the native code to continue authentication with the |token| and th e |sharedSecret|.
459 */ 482 */
460 public static native void nativeOnThirdPartyTokenFetched(String token, Strin g sharedSecret); 483 public static void onThirdPartyTokenFetched(String token, String sharedSecre t) {
484 if (!sConnected) {
485 return;
486 }
487
488 nativeOnThirdPartyTokenFetched(token, sharedSecret);
489 }
490
491 /** Passes authentication data to the native handling code. */
492 private static native void nativeOnThirdPartyTokenFetched(String token, Stri ng sharedSecret);
461 } 493 }
OLDNEW
« no previous file with comments | « remoting/android/java/src/org/chromium/chromoting/Chromoting.java ('k') | remoting/client/jni/chromoting_jni_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698