1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-26 06:11:19 +00:00

Fix parsing connectionServiceStatus (#49)

* Catch failures on gson-parsing SystemInfo

* Fix parsing connectionServiceStatus on recent syncthing version

* Add SystemStatusConnectionServiceStatusElement to model
This commit is contained in:
Catfriend1 2018-09-14 21:05:51 +02:00 committed by GitHub
parent 8a5e5d7e47
commit bdce748ac4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 3 deletions

View file

@ -9,7 +9,7 @@ import java.util.Map;
public class SystemStatus {
public long alloc;
public double cpuPercent;
public Map<String, Map<String, List<String>>> connectionServiceStatus;
public Map<String, SystemStatusConnectionServiceStatusElement> connectionServiceStatus;
public boolean discoveryEnabled;
public Map<String, String> discoveryErrors;
public int discoveryMethods;

View file

@ -0,0 +1,13 @@
package com.nutomic.syncthingandroid.model;
import java.util.List;
/**
* REST API endpoint "/rest/system/status"
* Part of JSON answer in field {@link SystemStatus#connectionServiceStatus}
*/
public class SystemStatusConnectionServiceStatusElement {
public String error;
public List<String> lanAddresses;
public List<String> wanAddresses;
}

View file

@ -505,8 +505,15 @@ public class RestApi {
* Requests and parses information about current system status and resource usage.
*/
public void getSystemStatus(OnResultListener1<SystemStatus> listener) {
new GetRequest(mContext, mUrl, GetRequest.URI_SYSTEM_STATUS, mApiKey, null, result ->
listener.onResult(new Gson().fromJson(result, SystemStatus.class)));
new GetRequest(mContext, mUrl, GetRequest.URI_SYSTEM_STATUS, mApiKey, null, result -> {
SystemStatus systemStatus;
try {
systemStatus = new Gson().fromJson(result, SystemStatus.class);
listener.onResult(systemStatus);
} catch (Exception e) {
Log.e(TAG, "getSystemStatus: Parsing REST API result failed. result=" + result);
}
});
}
public boolean isConfigLoaded() {