use of net.osmand.plus.backup.BackupError in project Osmand by osmandapp.
the class RegisterDeviceCommand method onProgressUpdate.
@Override
protected void onProgressUpdate(Object... values) {
for (OnRegisterDeviceListener listener : getListeners()) {
int status = (Integer) values[0];
String message = (String) values[1];
BackupError backupError = (BackupError) values[2];
listener.onRegisterDevice(status, message, backupError);
}
}
use of net.osmand.plus.backup.BackupError in project Osmand by osmandapp.
the class RegisterDeviceCommand method doInBackground.
@Override
protected Object doInBackground(Object... objects) {
Map<String, String> params = new HashMap<>();
BackupHelper helper = getHelper();
params.put("email", helper.getEmail());
String orderId = helper.getOrderId();
if (orderId != null) {
params.put("orderid", orderId);
}
String androidId = helper.getAndroidId();
if (!Algorithms.isEmpty(androidId)) {
params.put("deviceid", androidId);
}
params.put("token", token);
OperationLog operationLog = createOperationLog("registerDevice");
AndroidNetworkUtils.sendRequest(getApp(), DEVICE_REGISTER_URL, params, "Register device", false, true, (resultJson, error, resultCode) -> {
int status;
String message;
BackupError backupError = null;
if (resultCode != null && isTemporallyUnavailableErrorCode(resultCode)) {
message = "Device registration error code: " + resultCode;
error = "{\"error\":{\"errorCode\":" + STATUS_SERVER_TEMPORALLY_UNAVAILABLE_ERROR + ",\"message\":\"" + message + "\"}}";
}
if (!Algorithms.isEmpty(error)) {
backupError = new BackupError(error);
message = "Device registration error: " + backupError;
status = STATUS_SERVER_ERROR;
} else if (!Algorithms.isEmpty(resultJson)) {
OsmandSettings settings = getApp().getSettings();
try {
JSONObject result = new JSONObject(resultJson);
settings.BACKUP_DEVICE_ID.set(result.getString("id"));
settings.BACKUP_USER_ID.set(result.getString("userid"));
settings.BACKUP_NATIVE_DEVICE_ID.set(result.getString("deviceid"));
settings.BACKUP_ACCESS_TOKEN.set(result.getString("accesstoken"));
settings.BACKUP_ACCESS_TOKEN_UPDATE_TIME.set(result.getString("udpatetime"));
message = "Device have been registered successfully";
status = STATUS_SUCCESS;
} catch (JSONException e) {
message = "Device registration error: json parsing";
status = STATUS_PARSE_JSON_ERROR;
}
} else {
message = "Device registration error: empty response";
status = STATUS_EMPTY_RESPONSE_ERROR;
}
publishProgress(status, message, backupError);
operationLog.finishOperation(status + " " + message);
});
return null;
}
Aggregations