Skip to content

Migrate transport backend to auto @Encodable codegen. #1427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.google.android.datatransport.cct.internal.AndroidClientInfo;
import com.google.android.datatransport.cct.internal.BatchedLogRequest;
import com.google.android.datatransport.cct.internal.ClientInfo;
import com.google.android.datatransport.cct.internal.JsonBatchedLogRequestEncoder;
import com.google.android.datatransport.cct.internal.LogEvent;
import com.google.android.datatransport.cct.internal.LogRequest;
import com.google.android.datatransport.cct.internal.LogResponse;
Expand Down Expand Up @@ -88,7 +87,7 @@ final class CctTransportBackend implements TransportBackend {
private static final String KEY_FINGERPRINT = "fingerprint";
private static final String KEY_TIMEZONE_OFFSET = "tz-offset";

private final DataEncoder dataEncoder = JsonBatchedLogRequestEncoder.createJsonEncoder();
private final DataEncoder dataEncoder = BatchedLogRequest.createDataEncoder();

private final ConnectivityManager connectivityManager;
final URL endPoint;
Expand Down Expand Up @@ -197,7 +196,7 @@ private BatchedLogRequest getRequestBody(BackendRequest backendRequest) {

// set log source to either its numeric value or its name.
try {
requestBuilder.setSource(Integer.valueOf(entry.getKey()));
requestBuilder.setSource(Integer.parseInt(entry.getKey()));
} catch (NumberFormatException ex) {
requestBuilder.setSource(entry.getKey());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
@AutoValue
public abstract class AndroidClientInfo {
/** This comes from android.os.Build.VERSION.SDK_INT. */
public abstract int getSdkVersion();
@Nullable
public abstract Integer getSdkVersion();

/**
* Textual description of the client platform. e.g., "Nexus 4". This comes from
Expand Down Expand Up @@ -59,14 +60,14 @@ public abstract class AndroidClientInfo {

@NonNull
public static Builder builder() {
return new AutoValue_AndroidClientInfo.Builder().setSdkVersion(Integer.MIN_VALUE);
return new AutoValue_AndroidClientInfo.Builder();
}

@AutoValue.Builder
public abstract static class Builder {

@NonNull
public abstract Builder setSdkVersion(int value);
public abstract Builder setSdkVersion(@Nullable Integer value);

@NonNull
public abstract Builder setModel(@Nullable String value);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,28 @@

import androidx.annotation.NonNull;
import com.google.auto.value.AutoValue;
import com.google.firebase.encoders.DataEncoder;
import com.google.firebase.encoders.annotations.Encodable;
import com.google.firebase.encoders.json.JsonDataEncoderBuilder;
import java.util.List;

@AutoValue
@Encodable
public abstract class BatchedLogRequest {
@NonNull
@Encodable.Field(name = "logRequest")
public abstract List<LogRequest> getLogRequests();

@NonNull
public static BatchedLogRequest create(@NonNull List<LogRequest> logRequests) {
return new AutoValue_BatchedLogRequest(logRequests);
}

@NonNull
public static DataEncoder createDataEncoder() {
return new JsonDataEncoderBuilder()
.configureWith(AutoBatchedLogRequestEncoder.CONFIG)
.ignoreNullValues(true)
.build();
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public abstract class LogEvent {

public abstract long getEventTimeMs();

public abstract int getEventCode();
@Nullable
public abstract Integer getEventCode();

public abstract long getEventUptimeMs();

Expand Down Expand Up @@ -51,7 +52,7 @@ public static Builder jsonBuilder(@NonNull String sourceJsonExtension) {
}

private static Builder builder() {
return new AutoValue_LogEvent.Builder().setEventCode(Integer.MIN_VALUE);
return new AutoValue_LogEvent.Builder();
}

@AutoValue.Builder
Expand All @@ -60,7 +61,7 @@ public abstract static class Builder {
public abstract Builder setEventTimeMs(long value);

@NonNull
public abstract Builder setEventCode(int value);
public abstract Builder setEventCode(@Nullable Integer value);

@NonNull
public abstract Builder setEventUptimeMs(long value);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.auto.value.AutoValue;
import com.google.firebase.encoders.annotations.Encodable;
import java.util.List;

@AutoValue
Expand All @@ -34,20 +35,22 @@ public abstract class LogRequest {
@Nullable
public abstract ClientInfo getClientInfo();

public abstract int getLogSource();
@Nullable
public abstract Integer getLogSource();

@Nullable
public abstract String getLogSourceName();

@Nullable
@Encodable.Field(name = "logEvent")
public abstract List<LogEvent> getLogEvents();

@Nullable
public abstract QosTier getQosTier();

@NonNull
public static Builder builder() {
return new AutoValue_LogRequest.Builder().setLogSource(Integer.MIN_VALUE);
return new AutoValue_LogRequest.Builder();
}

@AutoValue.Builder
Expand All @@ -62,7 +65,7 @@ public abstract static class Builder {
public abstract Builder setClientInfo(@Nullable ClientInfo value);

@NonNull
abstract Builder setLogSource(int value);
abstract Builder setLogSource(@Nullable Integer value);

@NonNull
abstract Builder setLogSourceName(@Nullable String value);
Expand Down
Loading