Skip to content

Commit fdc83f0

Browse files
kyr0comann
authored andcommitted
Grand stability upgrade (#185)
* Log.d() for every catch clause and Throwable. Also removed all general Exception catches and catch specific (known) Exception classes instead. * Fixed reflection usage to fetch translated pokemon names * Catching RuntimeException to not crash on POGOProtos.Map.Fort.FortDataOuterClass$FortData$Builder missing method "getId". * Reduces the probability that RuntimeException missing "getId" is happening * Consistently printing stack traces * Proper log messages. * Added missing translation; fixed german translation * Finally a real fix for POGOProtos.Map.Fort.FortDataOuterClass$FortData$Builder * Drawing of circles (if activated) for radius search is now happening when the operation actually was successful. This means that you won't see a circle drawn when the under-laying specific operation failed for any reason. * Added check for NullPointerException; fixes issue #171
1 parent 31ea10d commit fdc83f0

File tree

10 files changed

+136
-72
lines changed

10 files changed

+136
-72
lines changed

app/src/main/java/com/omkarmoghe/pokemap/controllers/map/LocationManager.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private LocationManager(final Context context) {
4848
@Override
4949
public void onLocationChanged(Location newLocation) {
5050
location = newLocation;
51-
Log.d(TAG, "Location Found: " + location.getLatitude() + ", " + location.getLongitude());
51+
Log.d(TAG, "User location found: " + location.getLatitude() + ", " + location.getLongitude());
5252
notifyLocationChanged(location);
5353
}
5454
};
@@ -77,12 +77,14 @@ public void onConnected(@Nullable Bundle bundle) {
7777

7878
@Override
7979
public void onConnectionSuspended(int i) {
80+
Log.e(TAG, "Failed to fetch user location. Connection suspended, code: " + i);
8081
notifyLocationFetchFailed(null);
8182
}
8283
})
8384
.addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
8485
@Override
8586
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
87+
Log.e(TAG, "Failed to fetch user location. Connection result: " + connectionResult.getErrorMessage());
8688
notifyLocationFetchFailed(connectionResult);
8789
}
8890
})

app/src/main/java/com/omkarmoghe/pokemap/controllers/net/GoogleManager.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.omkarmoghe.pokemap.controllers.net;
22

3+
import android.util.Log;
4+
35
import okhttp3.HttpUrl;
46
import okhttp3.OkHttpClient;
57
import retrofit2.Call;
@@ -54,12 +56,19 @@ public void authUser(final LoginListener loginListener) {
5456
@Override
5557
public void onResponse(Call<GoogleService.AuthRequest> call, Response<GoogleService.AuthRequest> response) {
5658
GoogleService.AuthRequest body = response.body();
57-
loginListener.authRequested(body);
59+
60+
if (body != null) {
61+
loginListener.authRequested(body);
62+
} else {
63+
Log.e(TAG, "Google login failed while authenticating. response.body() is null.");
64+
loginListener.authFailed("Google login failed while authenticating");
65+
}
5866
}
5967

6068
@Override
6169
public void onFailure(Call<GoogleService.AuthRequest> call, Throwable t) {
6270
t.printStackTrace();
71+
Log.e(TAG, "Google authentication failed when calling authUser(). googleCallback's onFailure() threw: " + t.getMessage());
6372
loginListener.authFailed("Failed on getting the information for the user auth");
6473
}
6574
};
@@ -82,12 +91,19 @@ public void requestToken(String deviceCode, final LoginListener loginListener){
8291
Callback<GoogleService.TokenResponse> googleCallback = new Callback<GoogleService.TokenResponse>() {
8392
@Override
8493
public void onResponse(Call<GoogleService.TokenResponse> call, Response<GoogleService.TokenResponse> response) {
85-
loginListener.authSuccessful(response.body().getIdToken());
94+
95+
if (response.body() != null) {
96+
loginListener.authSuccessful(response.body().getIdToken());
97+
} else {
98+
Log.e(TAG, "Google login failed while fetching token. response.body() is null.");
99+
loginListener.authFailed("Google login failed while authenticating. Token missing.");
100+
}
86101
}
87102

88103
@Override
89104
public void onFailure(Call<GoogleService.TokenResponse> call, Throwable t) {
90105
t.printStackTrace();
106+
Log.e(TAG, "Google authentication failed while fetching request token using requestToken(). googleCallback's onFailure() threw: " + t.getMessage());
91107
loginListener.authFailed("Failed on requesting the id token");
92108
}
93109
};

app/src/main/java/com/omkarmoghe/pokemap/controllers/net/NetworkRequestLoggingInterceptor.java

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ private String convertRequestBodyToString(final Request request) {
5555
copy.body().writeTo(buffer);
5656
return buffer.readUtf8();
5757
} catch (final IOException e) {
58+
e.printStackTrace();
59+
Log.e(TAG, "Failed to convert request body to string via convertRequestBodyToString(). Raised: " + e.getMessage());
5860
return null;
5961
}
6062
}

app/src/main/java/com/omkarmoghe/pokemap/controllers/net/NianticManager.java

+31-11
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,17 @@ public void login(final String username, final String password, final LoginListe
126126
public void onResponse(Call<NianticService.LoginValues> call, Response<NianticService.LoginValues> response) {
127127
if(response.body() != null) {
128128
loginPTC(username, password, response.body(), loginListener);
129-
}else{
129+
} else {
130+
Log.e(TAG, "PTC login failed via login(). There was no response.body().");
130131
loginListener.authFailed("Fetching Pokemon Trainer Club's Login Url Values Failed");
131132
}
132133

133134
}
134135

135136
@Override
136137
public void onFailure(Call<NianticService.LoginValues> call, Throwable t) {
138+
t.printStackTrace();
139+
Log.e(TAG, "PTC login failed via login(). valuesCallback.onFailure() threw: " + t.getMessage());
137140
loginListener.authFailed("Fetching Pokemon Trainer Club's Login Url Values Failed");
138141
}
139142
};
@@ -170,12 +173,15 @@ public void onResponse(Call<NianticService.LoginResponse> call, Response<Niantic
170173
String ticket = location.split("ticket=")[1];
171174
requestToken(ticket, loginListener);
172175
} else {
176+
Log.e(TAG, "PTC login failed via loginPTC(). There was no location header in response.");
173177
loginListener.authFailed("Pokemon Trainer Club Login Failed");
174178
}
175179
}
176180

177181
@Override
178182
public void onFailure(Call<NianticService.LoginResponse> call, Throwable t) {
183+
t.printStackTrace();
184+
Log.e(TAG, "PTC login failed via loginPTC(). loginCallback.onFailure() threw: " + t.getMessage());
179185
loginListener.authFailed("Pokemon Trainer Club Login Failed");
180186
}
181187
};
@@ -204,17 +210,20 @@ public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response)
204210

205211
loginListener.authSuccessful(token);
206212
} else {
213+
Log.e(TAG, "PTC login failed while fetching a requestToken via requestToken(). Token is null.");
207214
loginListener.authFailed("Pokemon Trainer Club Login Failed");
208215
}
209216
} catch (IOException e) {
210217
e.printStackTrace();
218+
Log.e(TAG, "PTC login failed while fetching a requestToken authCallback.onResponse() raised: " + e.getMessage());
211219
loginListener.authFailed("Pokemon Trainer Club Authentication Failed");
212220
}
213221
}
214222

215223
@Override
216224
public void onFailure(Call<ResponseBody> call, Throwable t) {
217225
t.printStackTrace();
226+
Log.e(TAG, "PTC login failed while fetching a requestToken authCallback.onResponse() threw: " + t.getMessage());
218227
loginListener.authFailed("Pokemon Trainer Club Authentication Failed");
219228
}
220229
};
@@ -239,7 +248,9 @@ public void run() {
239248
mAuthInfo = new GoogleLogin(mPoGoClient).login(token);
240249
mPokemonGo = new PokemonGo(mAuthInfo, mPoGoClient);
241250
EventBus.getDefault().post(new LoginEventResult(true, mAuthInfo, mPokemonGo));
242-
} catch (Exception e) {
251+
} catch (RemoteServerException | LoginFailedException | RuntimeException e) {
252+
e.printStackTrace();
253+
Log.e(TAG, "Setting google auth token failed. setGoogleAuthToken() raised: " + e.getMessage());
243254
EventBus.getDefault().post(new LoginEventResult(false, null, null));
244255
}
245256
}
@@ -258,7 +269,9 @@ public void run() {
258269
mAuthInfo = new PtcLogin(mPoGoClient).login(token);
259270
mPokemonGo = new PokemonGo(mAuthInfo, mPoGoClient);
260271
EventBus.getDefault().post(new LoginEventResult(true, mAuthInfo, mPokemonGo));
261-
} catch (Exception e) {
272+
} catch (RemoteServerException | LoginFailedException | RuntimeException e) {
273+
e.printStackTrace();
274+
Log.e(TAG, "Failed to set the PTC auth token on PoGoAPI via setPTCAuthToken(). Raised: " + e.getMessage());
262275
EventBus.getDefault().post(new LoginEventResult(false, null, null));
263276
}
264277
}
@@ -273,7 +286,9 @@ public void run() {
273286
mAuthInfo = new PtcLogin(mPoGoClient).login(username, password);
274287
mPokemonGo = new PokemonGo(mAuthInfo, mPoGoClient);
275288
EventBus.getDefault().post(new LoginEventResult(true, mAuthInfo, mPokemonGo));
276-
} catch (Exception e) {
289+
} catch (RemoteServerException | LoginFailedException | RuntimeException e) {
290+
e.printStackTrace();
291+
Log.e(TAG, "Failed to PTC login using PoGoAPI via login(). Raised: " + e.getMessage());
277292
EventBus.getDefault().post(new LoginEventResult(false, null, null));
278293
}
279294
}
@@ -285,23 +300,28 @@ public void getMapInformation(final double lat, final double longitude, final do
285300
@Override
286301
public void run() {
287302
try {
303+
288304
if (mPokemonGo != null) {
289305

290-
//This fixes Exception of missind ID
291-
Thread.sleep(50);
306+
Thread.sleep(33);
292307
mPokemonGo.setLocation(lat, longitude, alt);
293-
EventBus.getDefault().post(new CatchablePokemonEvent(mPokemonGo.getMap().getCatchablePokemon()));
294-
EventBus.getDefault().post(new PokestopsEvent(mPokemonGo.getMap().getMapObjects().getPokestops()));
295-
308+
Thread.sleep(33);
309+
EventBus.getDefault().post(new CatchablePokemonEvent(mPokemonGo.getMap().getCatchablePokemon(), lat, longitude));
310+
Thread.sleep(33);
311+
EventBus.getDefault().post(new PokestopsEvent(mPokemonGo.getMap().getMapObjects().getPokestops()));
296312
}
297313

298314
} catch (LoginFailedException e) {
315+
e.printStackTrace();
316+
Log.e(TAG, "Failed to fetch map information via getMapInformation(). Login credentials wrong or user banned. Raised: " + e.getMessage());
299317
EventBus.getDefault().post(new LoginEventResult(false, null, null));
300318
} catch (RemoteServerException e) {
319+
e.printStackTrace();
320+
Log.e(TAG, "Failed to fetch map information via getMapInformation(). Remote server unreachable. Raised: " + e.getMessage());
301321
EventBus.getDefault().post(new ServerUnreachableEvent(e));
302-
} catch (NullPointerException e) {
322+
} catch (InterruptedException | RuntimeException e) {
303323
e.printStackTrace();
304-
} catch (Exception e) {
324+
Log.e(TAG, "Failed to fetch map information via getMapInformation(). PoGoAPI crashed. Raised: " + e.getMessage());
305325
EventBus.getDefault().post(new InternalExceptionEvent(e));
306326
}
307327
}

app/src/main/java/com/omkarmoghe/pokemap/controllers/service/PokemonNotificationService.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131

3232

3333
public class PokemonNotificationService extends Service{
34+
35+
private static final String TAG = "NotificationService";
36+
3437
private static final int notificationId = 2423235;
3538
private static final String ACTION_STOP_SELF = "com.omkarmoghe.pokemap.STOP_SERVICE";
3639

@@ -52,7 +55,7 @@ public IBinder onBind(Intent intent) {
5255

5356
@Override
5457
public void onCreate() {
55-
Log.d("PokeMap","Service.onCreate()");
58+
5659
EventBus.getDefault().register(this);
5760
createNotification();
5861

@@ -173,8 +176,9 @@ public void run() {
173176
}
174177
Thread.sleep(refreshRate);
175178

176-
}catch(Exception e){
179+
} catch (InterruptedException | NullPointerException e) {
177180
e.printStackTrace();
181+
Log.e(TAG, "Failed updating. UpdateRunnable.run() raised: " + e.getMessage());
178182
}
179183
}
180184
}

app/src/main/java/com/omkarmoghe/pokemap/models/events/CatchablePokemonEvent.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
public class CatchablePokemonEvent implements IEvent {
1111

1212
private List<CatchablePokemon> catchablePokemon;
13+
private double lat;
14+
private double longitude;
1315

14-
public CatchablePokemonEvent(List<CatchablePokemon> catchablePokemon) {
16+
public CatchablePokemonEvent(List<CatchablePokemon> catchablePokemon, double lat, double longitude) {
1517
this.catchablePokemon = catchablePokemon;
18+
this.lat = lat;
19+
this.longitude = longitude;
1620
}
1721

1822
public List<CatchablePokemon> getCatchablePokemon() {
@@ -22,4 +26,20 @@ public List<CatchablePokemon> getCatchablePokemon() {
2226
public void setCatchablePokemon(List<CatchablePokemon> catchablePokemon) {
2327
this.catchablePokemon = catchablePokemon;
2428
}
29+
30+
public double getLat() {
31+
return lat;
32+
}
33+
34+
public void setLat(double lat) {
35+
this.lat = lat;
36+
}
37+
38+
public double getLongitude() {
39+
return longitude;
40+
}
41+
42+
public void setLongitude(double longitude) {
43+
this.longitude = longitude;
44+
}
2545
}

app/src/main/java/com/omkarmoghe/pokemap/views/LoginActivity.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void authSuccessful(String authToken) {
8383

8484
@Override
8585
public void authFailed(String message) {
86-
Log.d(TAG, "authFailed() called with: message = [" + message + "]");
86+
Log.e(TAG, "Failed to authenticate. authFailed() called with: message = [" + message + "]");
8787
showAuthFailed();
8888
}
8989
};
@@ -101,8 +101,8 @@ public void authSuccessful(String authToken) {
101101
@Override
102102
public void authFailed(String message) {
103103
showProgress(false);
104-
Log.d(TAG, "authFailed() called with: message = [" + message + "]");
105-
Snackbar.make((View)mLoginFormView.getParent(), "Google Login Failed", Snackbar.LENGTH_LONG).show();
104+
Log.e(TAG, "Failed to authenticate. authFailed() called with: message = [" + message + "]");
105+
Snackbar.make((View)mLoginFormView.getParent(), R.string.google_login_failed, Snackbar.LENGTH_LONG).show();
106106
}
107107

108108
@Override

0 commit comments

Comments
 (0)