Skip to content

Commit 8da166e

Browse files
authored
Merge pull request #279 from Automattic/improve_user_agent
Improve UserAgent string for Tracks client
2 parents b70af22 + 1a03333 commit 8da166e

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

AutomatticTracks/src/main/java/com/automattic/android/tracks/DeviceInformation.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
private final JSONObject mImmutableDeviceInfoJSON;
6464
private final boolean mIsPortraitDefault;
6565

66+
private final String deviceUserAgent;
67+
6668
public DeviceInformation(Context context) {
6769
mContext = context;
6870

@@ -145,6 +147,9 @@ public DeviceInformation(Context context) {
145147
}
146148
}
147149

150+
// pre-populate Tracks client user agent
151+
deviceUserAgent = String.format("Nosara Client for %s; %s/%s", mModel, mOs, mOsVersion);
152+
148153
// pre-populate the JSON version with immutable info here for performance reasons
149154
mImmutableDeviceInfoJSON = new JSONObject();
150155
try {
@@ -406,4 +411,8 @@ public boolean isRtlLanguage() {
406411
public String getDeviceLanguage() {
407412
return mDeviceLanguage;
408413
}
414+
415+
public String getDeviceUserAgent() {
416+
return deviceUserAgent;
417+
}
409418
}

AutomatticTracks/src/main/java/com/automattic/android/tracks/TracksClient.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
public class TracksClient {
3333
public static final String LOGTAG = "NosaraClient";
3434

35-
protected static final String DEFAULT_USER_AGENT = "Nosara Client for Android";
3635
protected static final String NOSARA_REST_API_ENDPOINT_URL_V1_1 = "https://public-api.wordpress.com/rest/v1.1/";
3736
protected static final int DEFAULT_EVENTS_QUEUE_THRESHOLD = 9;
3837
protected static final int DEFAULT_EVENTS_QUEUE_MAX_SIZE = 10000;
@@ -53,7 +52,7 @@ public static enum NosaraUserType {ANON, WPCOM, SIMPLENOTE, POCKETCASTS, DAYONE}
5352
final static String PROTOCOL_CONTENT_TYPE = String.format("application/json; charset=%s", PROTOCOL_CHARSET);
5453

5554
private final Context mContext;
56-
private String mUserAgent = TracksClient.DEFAULT_USER_AGENT;
55+
private final String mUserAgent;
5756
private String mRestApiEndpointURL;
5857
private final String mTracksRestEndpointURL;
5958
private DeviceInformation deviceInformation;
@@ -89,6 +88,7 @@ private TracksClient(Context ctx) {
8988
mRestApiEndpointURL = NOSARA_REST_API_ENDPOINT_URL_V1_1;
9089
mTracksRestEndpointURL = getAbsoluteURL("tracks/record");
9190
deviceInformation = new DeviceInformation(ctx);
91+
mUserAgent = deviceInformation.getDeviceUserAgent();
9292

9393
// This is the thread that reads from the "fast" (in-memory) input events queue and actually writes data to the DB.
9494
Thread bufferCopyThread = new Thread(new Runnable() {
@@ -495,11 +495,6 @@ private String getAbsoluteURL(String url) {
495495
return String.format("%s%s", mRestApiEndpointURL, url);
496496
}
497497

498-
//Sets the User-Agent header to be sent with each future request.
499-
public void setUserAgent(String userAgent) {
500-
mUserAgent = userAgent;
501-
}
502-
503498
public String getUserAgent() {
504499
return mUserAgent;
505500
}

0 commit comments

Comments
 (0)