Skip to content

Commit 17b3fb4

Browse files
committed
Convert java API to be static, as instance API will not let us signIn repeatedly
1 parent c1e737f commit 17b3fb4

File tree

2 files changed

+21
-25
lines changed

2 files changed

+21
-25
lines changed

GoogleSignIn/Impl/GoogleSignInImpl.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static bool GoogleSignIn_Configure(HandleRef googleSignInHelper,
109109
bool requestIdToken, bool hidePopups, string[] additionalScopes,
110110
int scopeCount, string accountName)
111111
{
112-
googleSignInHelper.ToAndroidJavaObject().Call("configure",
112+
GoogleSignInHelper.CallStatic("configure",
113113
useGameSignIn,
114114
webClientId,
115115
requestAuthCode,
@@ -159,12 +159,12 @@ public void onCanceled() {
159159

160160
static IntPtr GoogleSignIn_SignIn(HandleRef self)
161161
{
162-
return self.ToAndroidJavaObject().Call<AndroidJavaObject>("signIn").GetRawObject();
162+
return GoogleSignInHelper.CallStatic<AndroidJavaObject>("signIn").GetRawObject();
163163
}
164164

165165
static IntPtr GoogleSignIn_SignInSilently(HandleRef self)
166166
{
167-
return self.ToAndroidJavaObject().Call<AndroidJavaObject>("signInSilently").GetRawObject();
167+
return GoogleSignInHelper.CallStatic<AndroidJavaObject>("signInSilently").GetRawObject();
168168
}
169169

170170
static void GoogleSignIn_Signout(HandleRef self)
@@ -175,18 +175,18 @@ static void GoogleSignIn_Signout(HandleRef self)
175175
authorizationResult?.Dispose();
176176
authorizationResult = null;
177177

178-
self.ToAndroidJavaObject().Call("signOut");
178+
GoogleSignInHelper.CallStatic("signOut");
179179
}
180180

181181
static void GoogleSignIn_Disconnect(HandleRef self) => throw new NotImplementedException();
182182

183-
internal static void GoogleSignIn_DisposeFuture(HandleRef self) => self.ToAndroidJavaObject()?.Call("cancel");
183+
internal static void GoogleSignIn_DisposeFuture(HandleRef self) => GoogleSignInHelper.CallStatic("cancel");
184184

185-
internal static bool GoogleSignIn_Pending(HandleRef self) => self.ToAndroidJavaObject()?.Call<bool>("isPending") ?? false;
185+
internal static bool GoogleSignIn_Pending(HandleRef self) => GoogleSignInHelper.CallStatic<bool>("isPending");
186186

187-
internal static IntPtr GoogleSignIn_Result(HandleRef self) => self.Handle;
187+
internal static IntPtr GoogleSignIn_Result(HandleRef self) => googleIdTokenCredential.GetRawObject();
188188

189-
internal static int GoogleSignIn_Status(HandleRef self) => self.ToAndroidJavaObject()?.Call<int>("getStatus") ?? 6;
189+
internal static int GoogleSignIn_Status(HandleRef self) => GoogleSignInHelper.CallStatic<int>("getStatus");
190190

191191
internal static string GoogleSignIn_GetServerAuthCode(HandleRef self) => authorizationResult?.Call<string>("getServerAuthCode");
192192

Plugins/Android/src/main/java/com/google/googlesignin/GoogleSignInHelper.java

+13-17
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package com.google.googlesignin;
1717

18-
import android.app.Activity;
19-
import android.os.Bundle;
2018
import android.os.CancellationSignal;
2119
import android.util.Log;
2220

@@ -37,10 +35,8 @@
3735
import com.google.android.gms.common.api.CommonStatusCodes;
3836
import com.google.android.gms.common.api.Scope;
3937
import com.google.android.gms.common.util.Strings;
40-
import com.google.android.gms.tasks.CancellationToken;
4138
import com.google.android.gms.tasks.OnCompleteListener;
4239
import com.google.android.gms.tasks.OnSuccessListener;
43-
import com.google.android.gms.tasks.OnTokenCanceledListener;
4440
import com.google.android.gms.tasks.SuccessContinuation;
4541
import com.google.android.gms.tasks.Task;
4642
import com.google.android.gms.tasks.TaskCompletionSource;
@@ -73,14 +69,14 @@ public static void enableDebugLogging(boolean flag) {
7369
loggingEnabled = flag;
7470
}
7571

76-
private CancellationSignal cancellationSignal;
77-
private Task<AuthorizationResult> task;
78-
private Function<Boolean, Task<AuthorizationResult>> signInFunction;
79-
public boolean isPending() {
72+
private static CancellationSignal cancellationSignal;
73+
private static Task<AuthorizationResult> task;
74+
private static Function<Boolean, Task<AuthorizationResult>> signInFunction;
75+
public static boolean isPending() {
8076
return task != null && !task.isComplete() && !task.isCanceled();
8177
}
8278

83-
public int getStatus() {
79+
public static int getStatus() {
8480
if(signInFunction == null)
8581
return CommonStatusCodes.DEVELOPER_ERROR;
8682

@@ -125,7 +121,7 @@ public int getStatus() {
125121
* C++ code, this is used
126122
* to correlate the response with the request.
127123
*/
128-
public void configure(
124+
public static void configure(
129125
boolean useGamesConfig,
130126
String webClientId,
131127
boolean requestAuthCode,
@@ -208,7 +204,7 @@ public Task<AuthorizationResult> then(GetCredentialResponse getCredentialRespons
208204
authorizationRequestBuilder.requestOfflineAccess(webClientId, forceRefreshToken);
209205

210206
int additionalCount = additionalScopes != null ? additionalScopes.length : 0;
211-
List<Scope> scopes = new ArrayList<>(3 + additionalCount);
207+
List<Scope> scopes = new ArrayList<>(2 + additionalCount);
212208
scopes.add(new Scope(Scopes.PROFILE));
213209
if (requestEmail)
214210
scopes.add(new Scope(Scopes.EMAIL));
@@ -238,17 +234,17 @@ public void onComplete(@NonNull Task<AuthorizationResult> _unused) {
238234
};
239235
}
240236

241-
public GoogleSignInHelper signIn() {
237+
public static Task<AuthorizationResult> signIn() {
242238
task = signInFunction.apply(false);
243-
return this;
239+
return task;
244240
}
245241

246-
public GoogleSignInHelper signInSilently() {
242+
public static Task<AuthorizationResult> signInSilently() {
247243
task = signInFunction.apply(true);
248-
return this;
244+
return task;
249245
}
250246

251-
public void cancel() {
247+
public static void cancel() {
252248
if(isPending() && cancellationSignal != null){
253249
cancellationSignal.cancel();
254250
cancellationSignal = null;
@@ -257,7 +253,7 @@ public void cancel() {
257253
task = null;
258254
}
259255

260-
public void signOut() {
256+
public static void signOut() {
261257
cancel();
262258

263259
CredentialManager.create(UnityPlayer.currentActivity).clearCredentialStateAsync(new ClearCredentialStateRequest(),

0 commit comments

Comments
 (0)