Index: remoting/android/java/src/org/chromium/chromoting/Chromoting.java |
diff --git a/remoting/android/java/src/org/chromium/chromoting/Chromoting.java b/remoting/android/java/src/org/chromium/chromoting/Chromoting.java |
index a10a17f43925f270b5305a27a3ee3f23d1865f13..f53926c37c75c294b40accc15849d6382199a722 100644 |
--- a/remoting/android/java/src/org/chromium/chromoting/Chromoting.java |
+++ b/remoting/android/java/src/org/chromium/chromoting/Chromoting.java |
@@ -36,6 +36,7 @@ import org.chromium.chromoting.accountswitcher.AccountSwitcher; |
import org.chromium.chromoting.accountswitcher.AccountSwitcherFactory; |
import org.chromium.chromoting.help.HelpContext; |
import org.chromium.chromoting.help.HelpSingleton; |
+import org.chromium.chromoting.jni.Client; |
import org.chromium.chromoting.jni.ConnectionListener; |
import org.chromium.chromoting.jni.JniInterface; |
@@ -117,6 +118,9 @@ public class Chromoting extends AppCompatActivity implements ConnectionListener, |
private AccountSwitcher mAccountSwitcher; |
+ /** The currently-connected Client, if any. */ |
+ private Client mClient; |
+ |
/** Shows a warning explaining that a Google account is required, then closes the activity. */ |
private void showNoAccountsDialog() { |
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
@@ -349,8 +353,14 @@ public class Chromoting extends AppCompatActivity implements ConnectionListener, |
@Override |
public void onDestroy() { |
super.onDestroy(); |
- JniInterface.disconnectFromHost(); |
mAccountSwitcher.destroy(); |
+ |
+ // TODO(lambroslambrou): Determine whether we really need to tear down the connection here, |
+ // so we can remove this code. |
+ if (mClient != null) { |
+ mClient.destroy(); |
+ mClient = null; |
+ } |
} |
/** Called when a child Activity exits and sends a result back to this Activity. */ |
@@ -444,6 +454,11 @@ public class Chromoting extends AppCompatActivity implements ConnectionListener, |
} |
private void connectToHost(HostInfo host) { |
+ if (mClient != null) { |
+ mClient.destroy(); |
+ } |
+ |
+ mClient = new Client(); |
mProgressIndicator = ProgressDialog.show( |
this, |
host.name, |
@@ -453,11 +468,15 @@ public class Chromoting extends AppCompatActivity implements ConnectionListener, |
new DialogInterface.OnCancelListener() { |
@Override |
public void onCancel(DialogInterface dialog) { |
- JniInterface.disconnectFromHost(); |
+ if (mClient != null) { |
+ mClient.destroy(); |
+ mClient = null; |
+ } |
} |
}); |
- SessionConnector connector = new SessionConnector(this, this, mHostListLoader); |
- mAuthenticator = new SessionAuthenticator(this, host); |
+ |
+ SessionConnector connector = new SessionConnector(mClient, this, this, mHostListLoader); |
+ mAuthenticator = new SessionAuthenticator(this, mClient, host); |
connector.connectToHost(mAccount, mToken, host, mAuthenticator, |
getPreferences(MODE_PRIVATE).getString(PREFERENCE_EXPERIMENTAL_FLAGS, "")); |
} |