Skip to content

Commit

Permalink
[google_sign_in] Android: Move GoogleSignInWrapper to a separate file. (
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenqiu1101 authored and Egor committed Nov 20, 2020
1 parent fc98623 commit dfbb988
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 26 deletions.
4 changes: 4 additions & 0 deletions packages/google_sign_in/google_sign_in/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.4.1

* Android: Move `GoogleSignInWrapper` to a separate class.

## 4.4.0

* Migrate to Android v2 embedder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,28 +659,3 @@ public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
}
}
}

/**
* A wrapper object that calls static method in GoogleSignIn.
*
* <p>Because GoogleSignIn uses static method mostly, which is hard for unit testing. We use this
* wrapper class to use instance method which calls the corresponding GoogleSignIn static methods.
*
* <p>Warning! This class should stay true that each method calls a GoogleSignIn static method with
* the same name and same parameters.
*/
class GoogleSignInWrapper {

GoogleSignInAccount getLastSignedInAccount(Context context) {
return GoogleSignIn.getLastSignedInAccount(context);
}

boolean hasPermissions(GoogleSignInAccount account, Scope scope) {
return GoogleSignIn.hasPermissions(account, scope);
}

void requestPermissions(
Activity activity, int requestCode, GoogleSignInAccount account, Scope[] scopes) {
GoogleSignIn.requestPermissions(activity, requestCode, account, scopes);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

package io.flutter.plugins.googlesignin;

import android.app.Activity;
import android.content.Context;
import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.common.api.Scope;

/**
* A wrapper object that calls static method in GoogleSignIn.
*
* <p>Because GoogleSignIn uses static method mostly, which is hard for unit testing. We use this
* wrapper class to use instance method which calls the corresponding GoogleSignIn static methods.
*
* <p>Warning! This class should stay true that each method calls a GoogleSignIn static method with
* the same name and same parameters.
*/
public class GoogleSignInWrapper {

GoogleSignInAccount getLastSignedInAccount(Context context) {
return GoogleSignIn.getLastSignedInAccount(context);
}

boolean hasPermissions(GoogleSignInAccount account, Scope scope) {
return GoogleSignIn.hasPermissions(account, scope);
}

void requestPermissions(
Activity activity, int requestCode, GoogleSignInAccount account, Scope[] scopes) {
GoogleSignIn.requestPermissions(activity, requestCode, account, scopes);
}
}
2 changes: 1 addition & 1 deletion packages/google_sign_in/google_sign_in/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: google_sign_in
description: Flutter plugin for Google Sign-In, a secure authentication system
for signing in with a Google account on Android and iOS.
homepage: https://github.com/flutter/plugins/tree/master/packages/google_sign_in/google_sign_in
version: 4.4.0
version: 4.4.1

flutter:
plugin:
Expand Down

0 comments on commit dfbb988

Please sign in to comment.