Index: remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java |
diff --git a/remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java b/remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java |
index ada724882f5fa49b461fc66f0da63628e06d701a..1b535cd288b3a79d31314ad54841b4c9baca3ced 100644 |
--- a/remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java |
+++ b/remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java |
@@ -45,14 +45,26 @@ public class JniInterface { |
/** The application context. Accessed on the UI thread. */ |
private static Activity sContext = null; |
+ /** Interface used for connection state notifications. */ |
+ public interface ConnectionListener { |
+ /** Notified on successful connection. */ |
+ void onConnected(); |
+ |
+ /** |
+ * Notified when the connection is disconnected due to host or network error. This is not |
+ * called if disconnection is initiated by the client. |
+ */ |
+ void onDisconnected(); |
Sergey Ulanov
2013/12/28 02:51:49
I think it's not enough to have just these two met
Lambros
2013/12/31 00:05:05
Done.
|
+ } |
+ |
/* |
* Connection-initiating state machine. |
*/ |
/** Whether the native code is attempting a connection. Accessed on the UI thread. */ |
private static boolean sConnected = false; |
- /** Callback to signal upon successful connection. Accessed on the UI thread. */ |
- private static Runnable sSuccessCallback = null; |
+ /** Notified upon successful connection or disconnection. Accessed on the UI thread. */ |
+ private static ConnectionListener sConnectionListener = null; |
/** Dialog for reporting connection progress. Accessed on the UI thread. */ |
private static ProgressDialog sProgressIndicator = null; |
@@ -108,10 +120,10 @@ public class JniInterface { |
/** Attempts to form a connection to the user-selected host. Called on the UI thread. */ |
public static void connectToHost(String username, String authToken, |
- String hostJid, String hostId, String hostPubkey, Runnable successCallback) { |
+ String hostJid, String hostId, String hostPubkey, ConnectionListener listener) { |
disconnectFromHost(); |
- sSuccessCallback = successCallback; |
+ sConnectionListener = listener; |
SharedPreferences prefs = sContext.getPreferences(Activity.MODE_PRIVATE); |
nativeConnect(username, authToken, hostJid, hostId, hostPubkey, |
prefs.getString(hostId + "_id", ""), prefs.getString(hostId + "_secret", "")); |
@@ -134,7 +146,7 @@ public class JniInterface { |
} |
nativeDisconnect(); |
- sSuccessCallback = null; |
+ sConnectionListener = null; |
sConnected = false; |
// Drop the reference to free the Bitmap for GC. |
@@ -182,12 +194,13 @@ public class JniInterface { |
getStringArray(R.array.protoc_states)[state], Toast.LENGTH_SHORT).show(); |
// Actually display the remote desktop. |
- sSuccessCallback.run(); |
+ sConnectionListener.onConnected(); |
} else { |
Toast.makeText(sContext, sContext.getResources().getStringArray( |
Sergey Ulanov
2013/12/28 02:51:49
Same here. JNI layer shouldn't handle UI. Let's mo
Lambros
2013/12/31 00:05:05
Done.
|
R.array.protoc_states)[state] + (error == 0 ? "" : ": " + |
sContext.getResources().getStringArray(R.array.protoc_errors)[error]), |
Toast.LENGTH_LONG).show(); |
+ sConnectionListener.onDisconnected(); |
} |
} |
} |