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

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: Move connection logic into Java Created 6 years, 5 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
« no previous file with comments | « remoting/android/java/src/org/chromium/chromoting/Chromoting.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 prefs.getString(hostId + "_id", ""), prefs.getString(hostId + "_ secret", "")); 179 prefs.getString(hostId + "_id", ""), prefs.getString(hostId + "_ secret", ""));
180 sConnected = true; 180 sConnected = true;
181 } 181 }
182 182
183 /** Performs the native portion of the connection. */ 183 /** Performs the native portion of the connection. */
184 private static native void nativeConnect(String username, String authToken, String hostJid, 184 private static native void nativeConnect(String username, String authToken, String hostJid,
185 String hostId, String hostPubkey, String pairId, String pairSecret); 185 String hostId, String hostPubkey, String pairId, String pairSecret);
186 186
187 /** Severs the connection and cleans up. Called on the UI thread. */ 187 /** Severs the connection and cleans up. Called on the UI thread. */
188 public static void disconnectFromHost() { 188 public static void disconnectFromHost() {
189 if (!sConnected) return; 189 if (!sConnected) return;
Jamie 2014/07/30 17:22:04 Nit: Elsewhere in this file, you've got braces for
Lambros 2014/08/12 01:27:35 Done.
190 190
191 sConnectionListener.onConnectionState(ConnectionListener.State.CLOSED, 191 sConnectionListener.onConnectionState(ConnectionListener.State.CLOSED,
192 ConnectionListener.Error.OK); 192 ConnectionListener.Error.OK);
193 193
194 disconnectFromHostWithoutNotification();
195 }
196
197 /** Same as disconnectFromHost() but without notifying the ConnectionListene r. */
198 private static void disconnectFromHostWithoutNotification() {
199 if (!sConnected) return;
200
194 nativeDisconnect(); 201 nativeDisconnect();
195 sConnectionListener = null; 202 sConnectionListener = null;
196 sConnected = false; 203 sConnected = false;
197 204
198 // Drop the reference to free the Bitmap for GC. 205 // Drop the reference to free the Bitmap for GC.
199 synchronized (sFrameLock) { 206 synchronized (sFrameLock) {
200 sFrameBitmap = null; 207 sFrameBitmap = null;
201 } 208 }
202 } 209 }
203 210
204 /** Performs the native portion of the cleanup. */ 211 /** Performs the native portion of the cleanup. */
205 private static native void nativeDisconnect(); 212 private static native void nativeDisconnect();
206 213
207 /** Reports whenever the connection status changes. Called on the UI thread. */ 214 /** Reports whenever the connection status changes. Called on the UI thread. */
208 @CalledByNative 215 @CalledByNative
209 private static void reportConnectionStatus(int state, int error) { 216 private static void reportConnectionStatus(int stateCode, int errorCode) {
210 sConnectionListener.onConnectionState(ConnectionListener.State.fromValue (state), 217 ConnectionListener.State state = ConnectionListener.State.fromValue(stat eCode);
211 ConnectionListener.Error.fromValue(error)); 218 ConnectionListener.Error error = ConnectionListener.Error.fromValue(erro rCode);
219 sConnectionListener.onConnectionState(state, error);
220 if (state == ConnectionListener.State.FAILED || state == ConnectionListe ner.State.CLOSED) {
221 // Disconnect from the host here, otherwise the next time connectToH ost() is called,
222 // it will try to disconnect, triggering an incorrect status notific ation.
223 disconnectFromHostWithoutNotification();
Jamie 2014/07/30 17:22:04 I don't like the fact that a method called reportC
Lambros 2014/08/12 01:27:35 Renamed the method (this touches some C++ files as
224 }
212 } 225 }
213 226
214 /** Prompts the user to enter a PIN. Called on the UI thread. */ 227 /** Prompts the user to enter a PIN. Called on the UI thread. */
215 @CalledByNative 228 @CalledByNative
216 private static void displayAuthenticationPrompt(boolean pairingSupported) { 229 private static void displayAuthenticationPrompt(boolean pairingSupported) {
217 AlertDialog.Builder pinPrompt = new AlertDialog.Builder(sContext); 230 AlertDialog.Builder pinPrompt = new AlertDialog.Builder(sContext);
218 pinPrompt.setTitle(sContext.getString(R.string.title_authenticate)); 231 pinPrompt.setTitle(sContext.getString(R.string.title_authenticate));
219 pinPrompt.setMessage(sContext.getString(R.string.pin_message_android)); 232 pinPrompt.setMessage(sContext.getString(R.string.pin_message_android));
220 pinPrompt.setIcon(android.R.drawable.ic_lock_lock); 233 pinPrompt.setIcon(android.R.drawable.ic_lock_lock);
221 234
222 final View pinEntry = sContext.getLayoutInflater().inflate(R.layout.pin_ dialog, null); 235 final View pinEntry = sContext.getLayoutInflater().inflate(R.layout.pin_ dialog, null);
223 pinPrompt.setView(pinEntry); 236 pinPrompt.setView(pinEntry);
224 237
225 final TextView pinTextView = (TextView)pinEntry.findViewById(R.id.pin_di alog_text); 238 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); 239 final CheckBox pinCheckBox = (CheckBox)pinEntry.findViewById(R.id.pin_di alog_check);
227 240
228 if (!pairingSupported) { 241 if (!pairingSupported) {
229 pinCheckBox.setChecked(false); 242 pinCheckBox.setChecked(false);
230 pinCheckBox.setVisibility(View.GONE); 243 pinCheckBox.setVisibility(View.GONE);
231 } 244 }
232 245
233 pinPrompt.setPositiveButton( 246 pinPrompt.setPositiveButton(
234 R.string.connect_button, new DialogInterface.OnClickListener() { 247 R.string.connect_button, new DialogInterface.OnClickListener() {
235 @Override 248 @Override
236 public void onClick(DialogInterface dialog, int which) { 249 public void onClick(DialogInterface dialog, int which) {
237 Log.i("jniiface", "User provided a PIN code"); 250 Log.i("jniiface", "User provided a PIN code");
238 nativeAuthenticationResponse(String.valueOf(pinTextView. getText()), 251 if (sConnected) {
239 pinCheckBox.isChecked(), Build.MODEL); 252 nativeAuthenticationResponse(String.valueOf(pinTextV iew.getText()),
253 pinCheckBox.isChecked(), Build.MODEL);
254 }
Jamie 2014/07/30 17:22:04 I think we should show an error in this case. It w
Lambros 2014/08/12 01:27:35 Done.
240 } 255 }
241 }); 256 });
242 257
243 pinPrompt.setNegativeButton( 258 pinPrompt.setNegativeButton(
244 R.string.cancel, new DialogInterface.OnClickListener() { 259 R.string.cancel, new DialogInterface.OnClickListener() {
245 @Override 260 @Override
246 public void onClick(DialogInterface dialog, int which) { 261 public void onClick(DialogInterface dialog, int which) {
247 Log.i("jniiface", "User canceled pin entry prompt"); 262 Log.i("jniiface", "User canceled pin entry prompt");
248 disconnectFromHost(); 263 disconnectFromHost();
249 } 264 }
(...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. */ 465 /** Pops up a third party login page to fetch the token required for authent ication. */
451 @CalledByNative 466 @CalledByNative
452 public static void fetchThirdPartyToken(String tokenUrl, String clientId, St ring scope) { 467 public static void fetchThirdPartyToken(String tokenUrl, String clientId, St ring scope) {
453 Chromoting app = (Chromoting) sContext; 468 Chromoting app = (Chromoting) sContext;
454 app.fetchThirdPartyToken(tokenUrl, clientId, scope); 469 app.fetchThirdPartyToken(tokenUrl, clientId, scope);
455 } 470 }
456 471
457 /** 472 /**
458 * Notify the native code to continue authentication with the |token| and th e |sharedSecret|. 473 * Notify the native code to continue authentication with the |token| and th e |sharedSecret|.
459 */ 474 */
460 public static native void nativeOnThirdPartyTokenFetched(String token, Strin g sharedSecret); 475 public static void onThirdPartyTokenFetched(String token, String sharedSecre t) {
476 if (!sConnected) {
477 return;
478 }
479
480 nativeOnThirdPartyTokenFetched(token, sharedSecret);
481 }
482
483 /** Passes authentication data to the native handling code. */
484 private static native void nativeOnThirdPartyTokenFetched(String token, Stri ng sharedSecret);
461 } 485 }
OLDNEW
« no previous file with comments | « remoting/android/java/src/org/chromium/chromoting/Chromoting.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698