33import POGOProtos .Networking .Envelopes .RequestEnvelopeOuterClass .RequestEnvelope .AuthInfo ;
44import com .pokegoapi .exceptions .LoginFailedException ;
55import com .pokegoapi .exceptions .RemoteServerException ;
6+ import com .pokegoapi .util .SystemTimeImpl ;
7+ import com .pokegoapi .util .Time ;
68import okhttp3 .OkHttpClient ;
79import svarzee .gps .gpsoauth .AuthToken ;
810import svarzee .gps .gpsoauth .Gpsoauth ;
@@ -23,9 +25,9 @@ public class GoogleAutoCredentialProvider extends CredentialProvider {
2325
2426 private final Gpsoauth gpsoauth ;
2527 private final String username ;
28+ private Time time ;
2629 private TokenInfo tokenInfo ;
2730
28-
2931 /**
3032 * Constructs credential provider using username and password
3133 *
@@ -34,11 +36,30 @@ public class GoogleAutoCredentialProvider extends CredentialProvider {
3436 * @throws LoginFailedException - login failed possibly due to invalid credentials
3537 * @throws RemoteServerException - some server/network failure
3638 */
39+ @ Deprecated
3740 public GoogleAutoCredentialProvider (OkHttpClient httpClient , String username , String password )
3841 throws LoginFailedException , RemoteServerException {
3942 this .gpsoauth = new Gpsoauth (httpClient );
4043 this .username = username ;
4144 this .tokenInfo = login (username , password );
45+ this .time = new SystemTimeImpl ();
46+ }
47+
48+ /**
49+ * Constructs credential provider using username and password
50+ *
51+ * @param username - google username
52+ * @param password - google password
53+ * @param Time - time object
54+ * @throws LoginFailedException - login failed possibly due to invalid credentials
55+ * @throws RemoteServerException - some server/network failure
56+ */
57+ public GoogleAutoCredentialProvider (OkHttpClient httpClient , String username , String password , Time time )
58+ throws LoginFailedException , RemoteServerException {
59+ this .gpsoauth = new Gpsoauth (httpClient );
60+ this .username = username ;
61+ this .tokenInfo = login (username , password );
62+ this .time = time ;
4263 }
4364
4465 private TokenInfo login (String username , String password )
@@ -86,7 +107,7 @@ public AuthInfo getAuthInfo() throws LoginFailedException, RemoteServerException
86107
87108 @ Override
88109 public boolean isTokenIdExpired () {
89- return tokenInfo .authToken .getExpiry () > System .currentTimeMillis () / 1000 - 60 ;
110+ return tokenInfo .authToken .getExpiry () > time .currentTimeMillis () / 1000 - 60 ;
90111 }
91112
92113 private static class TokenInfo {
0 commit comments