@@ -70,13 +70,16 @@ public void onResult(@NonNull GoogleSignInResult googleSignInResult) {
7070 return ;
7171 }
7272
73+ GoogleSignInFragment .this .tokenResult = new TokenResult (googleSignInResult .getSignInAccount (), googleSignInResult .getStatus ().getStatusCode ());
74+
7375 Status status = googleSignInResult .getStatus ();
7476 GoogleSignInAccount acct = googleSignInResult .isSuccess () ? googleSignInResult .getSignInAccount () : null ;
7577 if (acct == null ) {
7678 GoogleSignInHelper .logError ("Error with silentSignIn: " + status );
7779 }
7880
7981 GoogleSignInHelper .nativeOnResult (request .getHandle (),status != null ? status .getStatusCode () : CommonStatusCodes .INTERNAL_ERROR ,acct );
82+ request .cancel ();
8083 setState (State .READY );
8184 }
8285 });
@@ -122,6 +125,7 @@ public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
122125 }
123126
124127 public void disconnect () {
128+ this .tokenResult = null ;
125129 this .tokenPendingResult = null ;
126130 if (mGoogleApiClient != null ) {
127131 mGoogleApiClient .disconnect ();
@@ -156,16 +160,23 @@ public TokenRequest getRequest() {
156160 return request ;
157161 }
158162
163+ private TokenResult tokenResult = null ;
159164 private PendingResult <TokenResult > tokenPendingResult = null ;
160165
161166 public GoogleSignInAccount getAccount () {
167+ if (tokenResult != null )
168+ return tokenResult .getAccount ();
169+
162170 if (tokenPendingResult == null || tokenPendingResult .isCanceled ())
163171 return null ;
164172
165173 return tokenPendingResult .await (3 ,TimeUnit .SECONDS ).getAccount ();
166174 }
167175
168176 public int getStatus () {
177+ if (tokenResult != null )
178+ return tokenResult .getStatus ().getStatusCode ();
179+
169180 if (tokenPendingResult == null ) {
170181 return CommonStatusCodes .DEVELOPER_ERROR ;
171182 }
@@ -207,6 +218,7 @@ public static GoogleSignInFragment getInstance(Activity parentActivity) {
207218 public synchronized boolean submitRequest (TokenRequest request ) {
208219 if (this .request == null || this .state == State .READY ) {
209220 this .request = request ;
221+ this .tokenResult = null ;
210222 this .tokenPendingResult = request .getPendingResponse ();
211223 return true ;
212224 }
@@ -230,6 +242,7 @@ private synchronized void setState(State state) {
230242 */
231243 public void signOut () {
232244 clearRequest (true );
245+ this .tokenResult = null ;
233246 this .tokenPendingResult = null ;
234247 if (mGoogleApiClient != null ) {
235248 Auth .GoogleSignInApi .signOut (mGoogleApiClient );
@@ -303,6 +316,7 @@ private void processRequest(final boolean silent) {
303316 request .getPendingResponse ().setResultCallback (new ResultCallback <TokenResult >() {
304317 @ Override
305318 public void onResult (@ NonNull TokenResult tokenResult ) {
319+ GoogleSignInFragment .this .tokenResult = tokenResult ;
306320 GoogleSignInHelper .logDebug (
307321 String .format (
308322 Locale .getDefault (),
@@ -314,7 +328,8 @@ public void onResult(@NonNull TokenResult tokenResult) {
314328 tokenResult .getHandle (),
315329 tokenResult .getStatus ().getStatusCode (),
316330 tokenResult .getAccount ());
317- clearRequest (false );
331+ request .cancel ();
332+ setState (State .READY );
318333 }
319334 });
320335
0 commit comments