/** * Gets the current salt skew, this is used by {@link #getSalt()} to update the salt every 28 * days with a consistent window. This window size allows 4 week and 1 week analyses. */ @VisibleForTesting static int currentSaltSkew() { LocalDate now = LocalDate.from( Instant.ofEpochMilli(sDateProvider.now().getTime()).atZone(ZoneOffset.UTC)); // Unix epoch was on a Thursday, but we want Monday to be the day the salt is refreshed. long days = ChronoUnit.DAYS.between(EPOCH, now) + 3; return (int) (days / 28); }
/** Logs usage data provided in the @{link AndroidStudioEvent}. */ public void log(@NonNull AndroidStudioEvent.Builder studioEvent) { studioEvent.setStudioSessionId(sSessionId); if (mVersion != null && !studioEvent.hasProductDetails()) { studioEvent.setProductDetails(ProductDetails.newBuilder().setVersion(mVersion)); } long now = sDateProvider.now().getTime(); try { logDetails( ClientAnalytics.LogEvent.newBuilder() .setEventTimeMs(now) .setEventUptimeMs(now - mStartTimeMs) .setSourceExtension(studioEvent.build().toByteString())); } catch (NullPointerException exception) { // TODO: Temporary fix for http://b.android.com/224994. We should remove this try-catch // block once there is a permanent fix. logDetails( ClientAnalytics.LogEvent.newBuilder() .setEventTimeMs(now) .setEventUptimeMs(now - mStartTimeMs)); } }