Fixed a couple of crashes caused by accessing invalid data
This commit is contained in:
parent
5875c5a2de
commit
1848c82a46
1 changed files with 28 additions and 28 deletions
|
@ -101,7 +101,7 @@ public class NetworkService extends Service {
|
||||||
|
|
||||||
public int sendMessage(ApiCallable apiCallable, int requiredApi){
|
public int sendMessage(ApiCallable apiCallable, int requiredApi){
|
||||||
int apiId = 0;
|
int apiId = 0;
|
||||||
if(requiredApi != -1){
|
if(requiredApi != -1 && mApiIds.containsKey(requiredApi)){
|
||||||
apiId = mApiIds.get(requiredApi);
|
apiId = mApiIds.get(requiredApi);
|
||||||
}
|
}
|
||||||
ApiCall call = apiCallable.toApiCall(apiId, mCurrentId);
|
ApiCall call = apiCallable.toApiCall(apiId, mCurrentId);
|
||||||
|
@ -173,40 +173,40 @@ public class NetworkService extends Service {
|
||||||
|
|
||||||
// We will only handle messages that relate to the login and API accesses here.
|
// We will only handle messages that relate to the login and API accesses here.
|
||||||
if(response.result != null){
|
if(response.result != null){
|
||||||
if(mLastCall == RPC.CALL_LOGIN){
|
if(response.result instanceof Double || response.result instanceof Boolean){
|
||||||
isLoggedIn = true;
|
if(mLastCall == RPC.CALL_LOGIN){
|
||||||
|
isLoggedIn = true;
|
||||||
|
|
||||||
checkNextRequestedApiAccess();
|
checkNextRequestedApiAccess();
|
||||||
}else if(mLastCall == RPC.CALL_DATABASE){
|
}else if(mLastCall == RPC.CALL_DATABASE){
|
||||||
// Deserializing integer response
|
// Deserializing integer response
|
||||||
Type IntegerJsonResponse = new TypeToken<JsonRpcResponse<Integer>>(){}.getType();
|
Type IntegerJsonResponse = new TypeToken<JsonRpcResponse<Integer>>(){}.getType();
|
||||||
JsonRpcResponse<Integer> apiIdResponse = gson.fromJson(text, IntegerJsonResponse);
|
JsonRpcResponse<Integer> apiIdResponse = gson.fromJson(text, IntegerJsonResponse);
|
||||||
|
|
||||||
// Storing the "database" api id
|
// Storing the "database" api id
|
||||||
mApiIds.put(ApiAccess.API_DATABASE, apiIdResponse.result);
|
mApiIds.put(ApiAccess.API_DATABASE, apiIdResponse.result);
|
||||||
|
|
||||||
checkNextRequestedApiAccess();
|
checkNextRequestedApiAccess();
|
||||||
}else if(mLastCall == RPC.CALL_HISTORY){
|
}else if(mLastCall == RPC.CALL_HISTORY){
|
||||||
// Deserializing integer response
|
// Deserializing integer response
|
||||||
Type IntegerJsonResponse = new TypeToken<JsonRpcResponse<Integer>>(){}.getType();
|
Type IntegerJsonResponse = new TypeToken<JsonRpcResponse<Integer>>(){}.getType();
|
||||||
JsonRpcResponse<Integer> apiIdResponse = gson.fromJson(text, IntegerJsonResponse);
|
JsonRpcResponse<Integer> apiIdResponse = gson.fromJson(text, IntegerJsonResponse);
|
||||||
|
|
||||||
// Storing the "history" api id
|
// Storing the "history" api id
|
||||||
mApiIds.put(ApiAccess.API_HISTORY, apiIdResponse.result);
|
mApiIds.put(ApiAccess.API_HISTORY, apiIdResponse.result);
|
||||||
|
|
||||||
checkNextRequestedApiAccess();
|
checkNextRequestedApiAccess();
|
||||||
}else if(mLastCall == RPC.CALL_NETWORK_BROADCAST){
|
}else if(mLastCall == RPC.CALL_NETWORK_BROADCAST){
|
||||||
// Deserializing integer response
|
// Deserializing integer response
|
||||||
Type IntegerJsonResponse = new TypeToken<JsonRpcResponse<Integer>>(){}.getType();
|
Type IntegerJsonResponse = new TypeToken<JsonRpcResponse<Integer>>(){}.getType();
|
||||||
JsonRpcResponse<Integer> apiIdResponse = gson.fromJson(text, IntegerJsonResponse);
|
JsonRpcResponse<Integer> apiIdResponse = gson.fromJson(text, IntegerJsonResponse);
|
||||||
|
|
||||||
// Storing the "network_broadcast" api access
|
// Storing the "network_broadcast" api access
|
||||||
mApiIds.put(ApiAccess.API_NETWORK_BROADCAST, apiIdResponse.result);
|
mApiIds.put(ApiAccess.API_NETWORK_BROADCAST, apiIdResponse.result);
|
||||||
|
|
||||||
// All calls have been handled at this point
|
// All calls have been handled at this point
|
||||||
mLastCall = "";
|
mLastCall = "";
|
||||||
}else{
|
}
|
||||||
Log.d(TAG,"New unhandled message");
|
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
Log.w(TAG,"Error.Msg: "+response.error.message);
|
Log.w(TAG,"Error.Msg: "+response.error.message);
|
||||||
|
|
Loading…
Reference in a new issue