18
18
import POGOProtos .Enums .TutorialStateOuterClass .TutorialState ;
19
19
import POGOProtos .Networking .Envelopes .RequestEnvelopeOuterClass .RequestEnvelope .AuthInfo ;
20
20
import POGOProtos .Networking .Envelopes .SignatureOuterClass ;
21
- import POGOProtos .Networking .Requests .Messages .CheckChallenge .CheckChallengeMessage ;
21
+ import POGOProtos .Networking .Requests .Messages .CheckChallengeMessageOuterClass .CheckChallengeMessage ;
22
22
import POGOProtos .Networking .Requests .Messages .DownloadItemTemplatesMessageOuterClass .DownloadItemTemplatesMessage ;
23
23
import POGOProtos .Networking .Requests .Messages .LevelUpRewardsMessageOuterClass .LevelUpRewardsMessage ;
24
- import POGOProtos .Networking .Requests .Messages .VerifyChallenge .VerifyChallengeMessage ;
24
+ import POGOProtos .Networking .Requests .Messages .VerifyChallengeMessageOuterClass .VerifyChallengeMessage ;
25
25
import POGOProtos .Networking .Requests .RequestTypeOuterClass .RequestType ;
26
26
import POGOProtos .Networking .Responses .CheckChallengeResponseOuterClass .CheckChallengeResponse ;
27
27
import POGOProtos .Networking .Responses .DownloadRemoteConfigVersionResponseOuterClass .DownloadRemoteConfigVersionResponse ;
@@ -148,6 +148,9 @@ public PokemonGo(OkHttpClient client, Time time, long seed) {
148
148
client = client .newBuilder ()
149
149
.addNetworkInterceptor (new ClientInterceptor ())
150
150
.build ();
151
+ inventories = new Inventories (this );
152
+ settings = new Settings (this );
153
+ playerProfile = new PlayerProfile (this );
151
154
requestHandler = new RequestHandler (this , client );
152
155
map = new Map (this );
153
156
longitude = Double .NaN ;
@@ -195,6 +198,7 @@ public PokemonGo(OkHttpClient client) {
195
198
* @throws LoginFailedException When login fails
196
199
* @throws RemoteServerException When server fails
197
200
* @throws CaptchaActiveException if a captcha is active and the message can't be sent
201
+ * @throws HashException if an exception occurs while performing a hash request
198
202
*/
199
203
public void login (CredentialProvider credentialProvider , HashProvider hashProvider )
200
204
throws LoginFailedException , CaptchaActiveException , RemoteServerException , HashException {
@@ -208,10 +212,6 @@ public void login(CredentialProvider credentialProvider, HashProvider hashProvid
208
212
this .hashProvider = hashProvider ;
209
213
210
214
startTime = currentTimeMillis ();
211
- inventories = new Inventories (this );
212
- settings = new Settings (this );
213
- playerProfile = new PlayerProfile (this );
214
-
215
215
initialize ();
216
216
}
217
217
@@ -279,6 +279,10 @@ private void initialize() throws RemoteServerException, CaptchaActiveException,
279
279
playerProfile .setupAvatar ();
280
280
}
281
281
282
+ if (!heartbeat .active ()) {
283
+ heartbeat .start ();
284
+ }
285
+
282
286
if (!tutorialStates .contains (TutorialState .POKEMON_CAPTURE )) {
283
287
playerProfile .encounterTutorialComplete ();
284
288
}
@@ -301,6 +305,7 @@ private void initialize() throws RemoteServerException, CaptchaActiveException,
301
305
* @throws LoginFailedException When login fails
302
306
* @throws RemoteServerException When server fails
303
307
* @throws CaptchaActiveException if a captcha is active and the message can't be sent
308
+ * @throws HashException if an exception occurs while performing a hash request
304
309
*/
305
310
private void fireRequestBlock (ServerRequest request , RequestType ... exclude )
306
311
throws RemoteServerException , CaptchaActiveException , LoginFailedException , HashException {
@@ -318,6 +323,7 @@ private void fireRequestBlock(ServerRequest request, RequestType... exclude)
318
323
* @throws LoginFailedException When login fails
319
324
* @throws RemoteServerException When server fails
320
325
* @throws CaptchaActiveException if a captcha is active and the message can't be sent
326
+ * @throws HashException if an exception occurs while performing a hash request
321
327
*/
322
328
public void getAssetDigest () throws RemoteServerException , CaptchaActiveException , LoginFailedException ,
323
329
HashException {
@@ -346,14 +352,15 @@ private static long hash(String string) {
346
352
/**
347
353
* Fetches valid AuthInfo
348
354
*
355
+ * @param refresh if the AuthInfo object should be refreshed
349
356
* @return AuthInfo object
350
357
* @throws LoginFailedException when login fails
351
358
* @throws RemoteServerException When server fails
352
359
* @throws CaptchaActiveException if a captcha is active and the message can't be sent
353
360
*/
354
- public AuthInfo getAuthInfo ()
361
+ public AuthInfo getAuthInfo (boolean refresh )
355
362
throws LoginFailedException , CaptchaActiveException , RemoteServerException {
356
- return credentialProvider .getAuthInfo ();
363
+ return credentialProvider .getAuthInfo (refresh );
357
364
}
358
365
359
366
/**
@@ -380,9 +387,6 @@ public void setLocation(double latitude, double longitude, double altitude, doub
380
387
setLongitude (longitude );
381
388
setAltitude (altitude );
382
389
setAccuracy (accuracy );
383
- if (!heartbeat .active () && !Double .isNaN (latitude ) && !Double .isNaN (longitude )) {
384
- heartbeat .start ();
385
- }
386
390
}
387
391
388
392
public long currentTimeMillis () {
@@ -400,6 +404,10 @@ public void setLatitude(double value) {
400
404
throw new IllegalArgumentException ("latittude can not exceed +/- 90" );
401
405
}
402
406
latitude = value ;
407
+
408
+ if (heartbeat .active () && !Double .isNaN (latitude ) && !Double .isNaN (longitude )) {
409
+ heartbeat .beat ();
410
+ }
403
411
}
404
412
405
413
/**
@@ -413,6 +421,10 @@ public void setLongitude(double value) {
413
421
throw new IllegalArgumentException ("longitude can not exceed +/- 180" );
414
422
}
415
423
longitude = value ;
424
+
425
+ if (heartbeat .active () && !Double .isNaN (latitude ) && !Double .isNaN (longitude )) {
426
+ heartbeat .beat ();
427
+ }
416
428
}
417
429
418
430
/**
@@ -510,6 +522,7 @@ public void removeListener(Listener listener) {
510
522
* Returns all listeners for the given type.
511
523
*
512
524
* @param listenerType the type of listeners to return
525
+ * @param <T> the listener type
513
526
* @return all listeners for the given type
514
527
*/
515
528
public <T extends Listener > List <T > getListeners (Class <T > listenerType ) {
@@ -648,4 +661,12 @@ public void enqueueTask(Runnable task) {
648
661
public int getVersion () {
649
662
return hashProvider .getHashVersion ();
650
663
}
664
+
665
+ /**
666
+ * Exits this API
667
+ */
668
+ public void exit () {
669
+ heartbeat .exit ();
670
+ requestHandler .exit ();
671
+ }
651
672
}
0 commit comments