Skip to content

Commit

Permalink
#1351 - add X-Installation-ID HTTP request header
Browse files Browse the repository at this point in the history
  • Loading branch information
budowski committed Aug 18, 2024
1 parent 3536b59 commit 4a82bd0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public class INaturalistApp extends MultiDexApplication implements OnMapsSdkInit
private long mAppStartTime;

private boolean mCalledStartForeground = false;
private String mInstallationID = null;

public boolean hasCalledStartForeground() {
return mCalledStartForeground;
Expand Down Expand Up @@ -157,6 +158,10 @@ public void setShownOnboarding(boolean value) {
mOnboardingShownBefore = true;
}

public String getInstallationID() {
return mInstallationID;
}

@Override
public void onMapsSdkInitialized(@NonNull MapsInitializer.Renderer renderer) {
switch (renderer) {
Expand Down Expand Up @@ -328,6 +333,14 @@ public void run() {
setShownOnboarding(true);
}

String installationID = pref.getString("installation_id", null);
if (installationID == null) {
installationID = UUID.randomUUID().toString();
pref.edit().putString("installation_id", installationID).apply();
}

mInstallationID = installationID;

// Clear out any old cached photos
Intent serviceIntent = new Intent(INaturalistService.ACTION_CLEAR_OLD_PHOTOS_CACHE, null, this, INaturalistService.class);
INaturalistService.callService(this, serviceIntent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5864,6 +5864,7 @@ private JSONArray request(String url, String method, ArrayList<Pair<String, Stri
.build();
Request.Builder requestBuilder = new Request.Builder()
.addHeader("User-Agent", getUserAgent(mApp))
.addHeader("X-Installation-ID", mApp.getInstallationID())
.url(url);

mRetryAfterDate = null;
Expand Down

0 comments on commit 4a82bd0

Please sign in to comment.