@@ -70,13 +70,16 @@ public void onResult(@NonNull GoogleSignInResult googleSignInResult) {
70
70
return ;
71
71
}
72
72
73
+ GoogleSignInFragment .this .tokenResult = new TokenResult (googleSignInResult .getSignInAccount (), googleSignInResult .getStatus ().getStatusCode ());
74
+
73
75
Status status = googleSignInResult .getStatus ();
74
76
GoogleSignInAccount acct = googleSignInResult .isSuccess () ? googleSignInResult .getSignInAccount () : null ;
75
77
if (acct == null ) {
76
78
GoogleSignInHelper .logError ("Error with silentSignIn: " + status );
77
79
}
78
80
79
81
GoogleSignInHelper .nativeOnResult (request .getHandle (),status != null ? status .getStatusCode () : CommonStatusCodes .INTERNAL_ERROR ,acct );
82
+ request .cancel ();
80
83
setState (State .READY );
81
84
}
82
85
});
@@ -122,6 +125,7 @@ public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
122
125
}
123
126
124
127
public void disconnect () {
128
+ this .tokenResult = null ;
125
129
this .tokenPendingResult = null ;
126
130
if (mGoogleApiClient != null ) {
127
131
mGoogleApiClient .disconnect ();
@@ -156,16 +160,23 @@ public TokenRequest getRequest() {
156
160
return request ;
157
161
}
158
162
163
+ private TokenResult tokenResult = null ;
159
164
private PendingResult <TokenResult > tokenPendingResult = null ;
160
165
161
166
public GoogleSignInAccount getAccount () {
167
+ if (tokenResult != null )
168
+ return tokenResult .getAccount ();
169
+
162
170
if (tokenPendingResult == null || tokenPendingResult .isCanceled ())
163
171
return null ;
164
172
165
173
return tokenPendingResult .await (3 ,TimeUnit .SECONDS ).getAccount ();
166
174
}
167
175
168
176
public int getStatus () {
177
+ if (tokenResult != null )
178
+ return tokenResult .getStatus ().getStatusCode ();
179
+
169
180
if (tokenPendingResult == null ) {
170
181
return CommonStatusCodes .DEVELOPER_ERROR ;
171
182
}
@@ -207,6 +218,7 @@ public static GoogleSignInFragment getInstance(Activity parentActivity) {
207
218
public synchronized boolean submitRequest (TokenRequest request ) {
208
219
if (this .request == null || this .state == State .READY ) {
209
220
this .request = request ;
221
+ this .tokenResult = null ;
210
222
this .tokenPendingResult = request .getPendingResponse ();
211
223
return true ;
212
224
}
@@ -230,6 +242,7 @@ private synchronized void setState(State state) {
230
242
*/
231
243
public void signOut () {
232
244
clearRequest (true );
245
+ this .tokenResult = null ;
233
246
this .tokenPendingResult = null ;
234
247
if (mGoogleApiClient != null ) {
235
248
Auth .GoogleSignInApi .signOut (mGoogleApiClient );
@@ -303,6 +316,7 @@ private void processRequest(final boolean silent) {
303
316
request .getPendingResponse ().setResultCallback (new ResultCallback <TokenResult >() {
304
317
@ Override
305
318
public void onResult (@ NonNull TokenResult tokenResult ) {
319
+ GoogleSignInFragment .this .tokenResult = tokenResult ;
306
320
GoogleSignInHelper .logDebug (
307
321
String .format (
308
322
Locale .getDefault (),
@@ -314,7 +328,8 @@ public void onResult(@NonNull TokenResult tokenResult) {
314
328
tokenResult .getHandle (),
315
329
tokenResult .getStatus ().getStatusCode (),
316
330
tokenResult .getAccount ());
317
- clearRequest (false );
331
+ request .cancel ();
332
+ setState (State .READY );
318
333
}
319
334
});
320
335
0 commit comments