Move client version reporting to be more like a ClientToServerMessage:

pull/14/head
Sam Bosley 12 years ago
parent 58ec7a3001
commit 34fe492add

@ -22,12 +22,9 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.Log;
import com.timsu.astrid.R;
import com.todoroo.aacenc.ContextManager;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.RestClient;
@ -186,23 +183,6 @@ public class ActFmInvoker {
}
}
private String clientVersion = null;
private String getClientVersion() {
if (clientVersion == null) {
try {
PackageManager pm = ContextManager.getContext().getPackageManager();
PackageInfo pi = pm.getPackageInfo(Constants.PACKAGE, PackageManager.GET_META_DATA);
int version = pi.versionCode;
String versionName = pi.versionName;
clientVersion = "android-" + versionName + "-" + version;
} catch (Exception e) {
//
}
}
return clientVersion;
}
public JSONObject postSync(JSONArray data, MultipartEntity entity, String token) throws IOException,
ActFmServiceException {
try {
@ -216,10 +196,6 @@ public class ActFmInvoker {
entity.addPart("data", new StringBody(data.toString()));
entity.addPart("time", new StringBody(timeString));
String version = getClientVersion();
if (version != null)
entity.addPart("client_version", new StringBody(version));
String response = restClient.post(request, entity);
JSONObject object = new JSONObject(response);

@ -16,6 +16,8 @@ import org.json.JSONObject;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.Log;
import android.view.View;
import android.widget.ProgressBar;
@ -61,6 +63,7 @@ import com.todoroo.astrid.data.TaskListMetadataOutstanding;
import com.todoroo.astrid.data.TaskOutstanding;
import com.todoroo.astrid.data.User;
import com.todoroo.astrid.data.UserActivity;
import com.todoroo.astrid.utility.Constants;
import com.todoroo.astrid.widget.TasksWidget;
public class ActFmSyncThread {
@ -318,6 +321,8 @@ public class ActFmSyncThread {
continue;
}
payload.put(0, getClientVersion());
try {
JSONObject response = actFmInvoker.postSync(payload, entity, token);
// process responses
@ -401,6 +406,27 @@ public class ActFmSyncThread {
}
}
private String clientVersion = null;
@SuppressWarnings("nls")
private String getClientVersion() {
if (clientVersion == null) {
try {
PackageManager pm = ContextManager.getContext().getPackageManager();
PackageInfo pi = pm.getPackageInfo(Constants.PACKAGE, PackageManager.GET_META_DATA);
JSONObject message = new JSONObject();
message.put(ClientToServerMessage.TYPE_KEY, "ClientVersion");
message.put("platform", "android");
message.put("versionName", pi.versionName);
message.put("versionCode", pi.versionCode);
clientVersion = message.toString();
} catch (Exception e) {
//
}
}
return clientVersion;
}
public void repopulateQueueFromOutstandingTables() {
syncLog("Constructing queue from outstanding tables"); //$NON-NLS-1$
constructChangesHappenedFromOutstandingTable(Task.class, taskDao, taskOutstandingDao);

Loading…
Cancel
Save