| Index: remoting/android/host/src/org/chromium/chromoting/host/MainActivity.java
|
| diff --git a/remoting/android/host/src/org/chromium/chromoting/host/MainActivity.java b/remoting/android/host/src/org/chromium/chromoting/host/MainActivity.java
|
| index 649fd42cfb1febfb164ab3e6df88d101b45b3e95..dacf21fb9e84b54e46e698d45b1df40472d61f7e 100644
|
| --- a/remoting/android/host/src/org/chromium/chromoting/host/MainActivity.java
|
| +++ b/remoting/android/host/src/org/chromium/chromoting/host/MainActivity.java
|
| @@ -4,14 +4,30 @@
|
|
|
| package org.chromium.chromoting.host;
|
|
|
| +import android.accounts.AccountManager;
|
| +import android.content.Intent;
|
| import android.os.Bundle;
|
| import android.support.v7.app.AppCompatActivity;
|
| import android.support.v7.widget.Toolbar;
|
| +import android.view.View;
|
| +
|
| +import org.chromium.base.Log;
|
| +import org.chromium.chromoting.base.OAuthTokenFetcher;
|
| +import org.chromium.chromoting.host.jni.Host;
|
|
|
| /**
|
| * Main screen of the Chromoting Host application.
|
| */
|
| public class MainActivity extends AppCompatActivity {
|
| + private static final String TAG = "host";
|
| +
|
| + /** Scope to use when fetching the OAuth token. */
|
| + private static final String TOKEN_SCOPE = "oauth2:https://www.googleapis.com/auth/googletalk";
|
| +
|
| + private static final int REQUEST_CODE_CHOOSE_ACCOUNT = 0;
|
| +
|
| + private Host mHost;
|
| + private String mAccountName;
|
|
|
| @Override
|
| public void onCreate(Bundle savedInstanceState) {
|
| @@ -21,5 +37,45 @@ public class MainActivity extends AppCompatActivity {
|
|
|
| Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
| setSupportActionBar(toolbar);
|
| +
|
| + if (mHost == null) {
|
| + mHost = new Host();
|
| + }
|
| + }
|
| +
|
| + @SuppressWarnings("deprecation")
|
| + public void onShareClicked(View view) {
|
| + Intent intent = AccountManager.newChooseAccountIntent(
|
| + null, null, new String[] {"com.google"}, false, null, null, null, null);
|
| + startActivityForResult(intent, REQUEST_CODE_CHOOSE_ACCOUNT);
|
| + }
|
| +
|
| + public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
| + if (resultCode != RESULT_OK) {
|
| + return;
|
| + }
|
| +
|
| + if (requestCode == REQUEST_CODE_CHOOSE_ACCOUNT) {
|
| + mAccountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
|
| + requestAuthToken();
|
| + } else if (requestCode == OAuthTokenFetcher.REQUEST_CODE_RECOVER_FROM_OAUTH_ERROR) {
|
| + // User gave OAuth permission to this app (or recovered from any OAuth failure),
|
| + // so retry fetching the token.
|
| + requestAuthToken();
|
| + }
|
| + }
|
| +
|
| + private void requestAuthToken() {
|
| + new OAuthTokenFetcher(this, mAccountName, TOKEN_SCOPE, new OAuthTokenFetcher.Callback() {
|
| + @Override
|
| + public void onTokenFetched(String token) {
|
| + mHost.connect(mAccountName, token);
|
| + }
|
| +
|
| + @Override
|
| + public void onError(OAuthTokenFetcher.Error error) {
|
| + Log.e(TAG, "Error fetching token: %s", error.name());
|
| + }
|
| + }).fetch();
|
| }
|
| }
|
|
|