OLD | NEW |
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; | 5 package org.chromium.chromoting; |
6 | 6 |
7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.app.AlertDialog; | 8 import android.app.AlertDialog; |
9 import android.app.ProgressDialog; | 9 import android.app.ProgressDialog; |
10 import android.content.DialogInterface; | 10 import android.content.DialogInterface; |
(...skipping 18 matching lines...) Expand all Loading... |
29 import android.widget.LinearLayout; | 29 import android.widget.LinearLayout; |
30 import android.widget.ListView; | 30 import android.widget.ListView; |
31 import android.widget.Toast; | 31 import android.widget.Toast; |
32 | 32 |
33 import org.chromium.base.ApiCompatibilityUtils; | 33 import org.chromium.base.ApiCompatibilityUtils; |
34 import org.chromium.base.Log; | 34 import org.chromium.base.Log; |
35 import org.chromium.chromoting.accountswitcher.AccountSwitcher; | 35 import org.chromium.chromoting.accountswitcher.AccountSwitcher; |
36 import org.chromium.chromoting.accountswitcher.AccountSwitcherFactory; | 36 import org.chromium.chromoting.accountswitcher.AccountSwitcherFactory; |
37 import org.chromium.chromoting.help.HelpContext; | 37 import org.chromium.chromoting.help.HelpContext; |
38 import org.chromium.chromoting.help.HelpSingleton; | 38 import org.chromium.chromoting.help.HelpSingleton; |
39 import org.chromium.chromoting.jni.Client; | |
40 import org.chromium.chromoting.jni.ConnectionListener; | 39 import org.chromium.chromoting.jni.ConnectionListener; |
41 import org.chromium.chromoting.jni.JniInterface; | 40 import org.chromium.chromoting.jni.JniInterface; |
42 | 41 |
43 import java.util.ArrayList; | 42 import java.util.ArrayList; |
44 import java.util.Arrays; | 43 import java.util.Arrays; |
45 | 44 |
46 /** | 45 /** |
47 * The user interface for querying and displaying a user's host list from the di
rectory server. It | 46 * The user interface for querying and displaying a user's host list from the di
rectory server. It |
48 * also requests and renews authentication tokens using the system account manag
er. | 47 * also requests and renews authentication tokens using the system account manag
er. |
49 */ | 48 */ |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 * while a token is being fetched. | 110 * while a token is being fetched. |
112 */ | 111 */ |
113 private boolean mWaitingForAuthToken = false; | 112 private boolean mWaitingForAuthToken = false; |
114 | 113 |
115 private DrawerLayout mDrawerLayout; | 114 private DrawerLayout mDrawerLayout; |
116 | 115 |
117 private ActionBarDrawerToggle mDrawerToggle; | 116 private ActionBarDrawerToggle mDrawerToggle; |
118 | 117 |
119 private AccountSwitcher mAccountSwitcher; | 118 private AccountSwitcher mAccountSwitcher; |
120 | 119 |
121 /** The currently-connected Client, if any. */ | |
122 private Client mClient; | |
123 | |
124 /** Shows a warning explaining that a Google account is required, then close
s the activity. */ | 120 /** Shows a warning explaining that a Google account is required, then close
s the activity. */ |
125 private void showNoAccountsDialog() { | 121 private void showNoAccountsDialog() { |
126 AlertDialog.Builder builder = new AlertDialog.Builder(this); | 122 AlertDialog.Builder builder = new AlertDialog.Builder(this); |
127 builder.setMessage(R.string.noaccounts_message); | 123 builder.setMessage(R.string.noaccounts_message); |
128 builder.setPositiveButton(R.string.noaccounts_add_account, | 124 builder.setPositiveButton(R.string.noaccounts_add_account, |
129 new DialogInterface.OnClickListener() { | 125 new DialogInterface.OnClickListener() { |
130 @SuppressLint("InlinedApi") | 126 @SuppressLint("InlinedApi") |
131 @Override | 127 @Override |
132 public void onClick(DialogInterface dialog, int id) { | 128 public void onClick(DialogInterface dialog, int id) { |
133 Intent intent = new Intent(Settings.ACTION_ADD_ACCOUNT); | 129 Intent intent = new Intent(Settings.ACTION_ADD_ACCOUNT); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 preferences.putString(prefName, recents[i]); | 342 preferences.putString(prefName, recents[i]); |
347 } | 343 } |
348 | 344 |
349 preferences.apply(); | 345 preferences.apply(); |
350 } | 346 } |
351 | 347 |
352 /** Called when the activity is finally finished. */ | 348 /** Called when the activity is finally finished. */ |
353 @Override | 349 @Override |
354 public void onDestroy() { | 350 public void onDestroy() { |
355 super.onDestroy(); | 351 super.onDestroy(); |
| 352 JniInterface.disconnectFromHost(); |
356 mAccountSwitcher.destroy(); | 353 mAccountSwitcher.destroy(); |
357 | |
358 // TODO(lambroslambrou): Determine whether we really need to tear down t
he connection here, | |
359 // so we can remove this code. | |
360 if (mClient != null) { | |
361 mClient.destroy(); | |
362 mClient = null; | |
363 } | |
364 } | 354 } |
365 | 355 |
366 /** Called when a child Activity exits and sends a result back to this Activ
ity. */ | 356 /** Called when a child Activity exits and sends a result back to this Activ
ity. */ |
367 @Override | 357 @Override |
368 public void onActivityResult(int requestCode, int resultCode, Intent data) { | 358 public void onActivityResult(int requestCode, int resultCode, Intent data) { |
369 mAccountSwitcher.onActivityResult(requestCode, resultCode, data); | 359 mAccountSwitcher.onActivityResult(requestCode, resultCode, data); |
370 | 360 |
371 if (requestCode == OAuthTokenFetcher.REQUEST_CODE_RECOVER_FROM_OAUTH_ERR
OR) { | 361 if (requestCode == OAuthTokenFetcher.REQUEST_CODE_RECOVER_FROM_OAUTH_ERR
OR) { |
372 if (resultCode == RESULT_OK) { | 362 if (resultCode == RESULT_OK) { |
373 // User gave OAuth permission to this app (or recovered from any
OAuth failure), | 363 // User gave OAuth permission to this app (or recovered from any
OAuth failure), |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 HostInfo host = mHosts[index]; | 437 HostInfo host = mHosts[index]; |
448 if (host.isOnline) { | 438 if (host.isOnline) { |
449 connectToHost(host); | 439 connectToHost(host); |
450 } else { | 440 } else { |
451 String tooltip = host.getHostOfflineReasonText(this); | 441 String tooltip = host.getHostOfflineReasonText(this); |
452 Toast.makeText(this, tooltip, Toast.LENGTH_SHORT).show(); | 442 Toast.makeText(this, tooltip, Toast.LENGTH_SHORT).show(); |
453 } | 443 } |
454 } | 444 } |
455 | 445 |
456 private void connectToHost(HostInfo host) { | 446 private void connectToHost(HostInfo host) { |
457 if (mClient != null) { | |
458 mClient.destroy(); | |
459 } | |
460 | |
461 mClient = new Client(); | |
462 mProgressIndicator = ProgressDialog.show( | 447 mProgressIndicator = ProgressDialog.show( |
463 this, | 448 this, |
464 host.name, | 449 host.name, |
465 getString(R.string.footer_connecting), | 450 getString(R.string.footer_connecting), |
466 true, | 451 true, |
467 true, | 452 true, |
468 new DialogInterface.OnCancelListener() { | 453 new DialogInterface.OnCancelListener() { |
469 @Override | 454 @Override |
470 public void onCancel(DialogInterface dialog) { | 455 public void onCancel(DialogInterface dialog) { |
471 if (mClient != null) { | 456 JniInterface.disconnectFromHost(); |
472 mClient.destroy(); | |
473 mClient = null; | |
474 } | |
475 } | 457 } |
476 }); | 458 }); |
477 | 459 SessionConnector connector = new SessionConnector(this, this, mHostListL
oader); |
478 SessionConnector connector = new SessionConnector(mClient, this, this, m
HostListLoader); | 460 mAuthenticator = new SessionAuthenticator(this, host); |
479 mAuthenticator = new SessionAuthenticator(this, mClient, host); | |
480 connector.connectToHost(mAccount, mToken, host, mAuthenticator, | 461 connector.connectToHost(mAccount, mToken, host, mAuthenticator, |
481 getPreferences(MODE_PRIVATE).getString(PREFERENCE_EXPERIMENTAL_F
LAGS, "")); | 462 getPreferences(MODE_PRIVATE).getString(PREFERENCE_EXPERIMENTAL_F
LAGS, "")); |
482 } | 463 } |
483 | 464 |
484 private void refreshHostList() { | 465 private void refreshHostList() { |
485 if (mWaitingForAuthToken) { | 466 if (mWaitingForAuthToken) { |
486 return; | 467 return; |
487 } | 468 } |
488 | 469 |
489 mTriedNewAuthToken = false; | 470 mTriedNewAuthToken = false; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 // Unreachable, but required by Google Java style and findbugs. | 621 // Unreachable, but required by Google Java style and findbugs. |
641 assert false : "Unreached"; | 622 assert false : "Unreached"; |
642 } | 623 } |
643 | 624 |
644 if (dismissProgress && mProgressIndicator != null) { | 625 if (dismissProgress && mProgressIndicator != null) { |
645 mProgressIndicator.dismiss(); | 626 mProgressIndicator.dismiss(); |
646 mProgressIndicator = null; | 627 mProgressIndicator = null; |
647 } | 628 } |
648 } | 629 } |
649 } | 630 } |
OLD | NEW |