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

Unified Diff: remoting/android/host/src/org/chromium/chromoting/host/MainActivity.java

Issue 1888653002: [remoting android] Initialize It2Me host and implement Connect() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase/re-upload since Reitveld is confused Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
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();
}
}
« no previous file with comments | « remoting/android/host/res/layout/main.xml ('k') | remoting/android/host/src/org/chromium/chromoting/host/jni/Host.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698