Skip to content

Set fis as an unloader #3222

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 7 commits into from
Dec 13, 2021
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 @@ -25,7 +25,7 @@
import com.google.android.gms.tasks.Tasks;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.heartbeatinfo.HeartBeatInfo;
import com.google.firebase.heartbeatinfo.HeartBeatController;
import com.google.firebase.inject.Provider;
import com.google.firebase.installations.FirebaseInstallationsException.Status;
import com.google.firebase.installations.internal.FidListener;
Expand All @@ -36,7 +36,6 @@
import com.google.firebase.installations.remote.FirebaseInstallationServiceClient;
import com.google.firebase.installations.remote.InstallationResponse;
import com.google.firebase.installations.remote.TokenResult;
import com.google.firebase.platforminfo.UserAgentPublisher;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
Expand Down Expand Up @@ -124,9 +123,7 @@ public Thread newThread(Runnable r) {

/** package private constructor. */
FirebaseInstallations(
FirebaseApp firebaseApp,
@NonNull Provider<UserAgentPublisher> publisher,
@NonNull Provider<HeartBeatInfo> heartbeatInfo) {
FirebaseApp firebaseApp, @NonNull Provider<HeartBeatController> heartBeatProvider) {
this(
new ThreadPoolExecutor(
CORE_POOL_SIZE,
Expand All @@ -137,7 +134,7 @@ public Thread newThread(Runnable r) {
THREAD_FACTORY),
firebaseApp,
new FirebaseInstallationServiceClient(
firebaseApp.getApplicationContext(), publisher, heartbeatInfo),
firebaseApp.getApplicationContext(), heartBeatProvider),
new PersistedInstallation(firebaseApp),
Utils.getInstance(),
new IidStore(firebaseApp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import com.google.firebase.components.Component;
import com.google.firebase.components.ComponentRegistrar;
import com.google.firebase.components.Dependency;
import com.google.firebase.heartbeatinfo.HeartBeatInfo;
import com.google.firebase.heartbeatinfo.HeartBeatConsumerComponent;
import com.google.firebase.heartbeatinfo.HeartBeatController;
import com.google.firebase.platforminfo.LibraryVersionComponent;
import com.google.firebase.platforminfo.UserAgentPublisher;
import java.util.Arrays;
import java.util.List;

Expand All @@ -34,15 +34,13 @@ public List<Component<?>> getComponents() {
return Arrays.asList(
Component.builder(FirebaseInstallationsApi.class)
.add(Dependency.required(FirebaseApp.class))
.add(Dependency.optionalProvider(HeartBeatInfo.class))
.add(Dependency.optionalProvider(UserAgentPublisher.class))
.add(Dependency.optionalProvider(HeartBeatController.class))
.factory(
c ->
new FirebaseInstallations(
c.get(FirebaseApp.class),
c.getProvider(UserAgentPublisher.class),
c.getProvider(HeartBeatInfo.class)))
c.get(FirebaseApp.class), c.getProvider(HeartBeatController.class)))
.build(),
HeartBeatConsumerComponent.create(),
LibraryVersionComponent.create("fire-installations", BuildConfig.VERSION_NAME));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@
import com.google.android.gms.common.util.AndroidUtilsLight;
import com.google.android.gms.common.util.Hex;
import com.google.android.gms.common.util.VisibleForTesting;
import com.google.firebase.heartbeatinfo.HeartBeatInfo;
import com.google.firebase.heartbeatinfo.HeartBeatInfo.HeartBeat;
import com.google.android.gms.tasks.Tasks;
import com.google.firebase.heartbeatinfo.HeartBeatController;
import com.google.firebase.inject.Provider;
import com.google.firebase.installations.FirebaseInstallationsException;
import com.google.firebase.installations.FirebaseInstallationsException.Status;
import com.google.firebase.installations.remote.InstallationResponse.ResponseCode;
import com.google.firebase.platforminfo.UserAgentPublisher;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -46,6 +45,7 @@
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.util.concurrent.ExecutionException;
import java.util.regex.Pattern;
import java.util.zip.GZIPOutputStream;
import org.json.JSONException;
Expand Down Expand Up @@ -88,8 +88,7 @@ public class FirebaseInstallationServiceClient {
/** Heartbeat tag for firebase installations. */
private static final String FIREBASE_INSTALLATIONS_ID_HEARTBEAT_TAG = "fire-installations-id";

private static final String HEART_BEAT_HEADER = "x-firebase-client-log-type";
private static final String USER_AGENT_HEADER = "x-firebase-client";
private static final String HEART_BEAT_HEADER = "x-firebase-client";

private static final String X_ANDROID_PACKAGE_HEADER_KEY = "X-Android-Package";
private static final String X_ANDROID_CERT_HEADER_KEY = "X-Android-Cert";
Expand All @@ -114,17 +113,13 @@ public class FirebaseInstallationServiceClient {
static final String PARSING_EXPIRATION_TIME_ERROR_MESSAGE = "Invalid Expiration Timestamp.";

private final Context context;
private final Provider<UserAgentPublisher> userAgentPublisher;
private final Provider<HeartBeatInfo> heartbeatInfo;
private final Provider<HeartBeatController> heartBeatProvider;
private final RequestLimiter requestLimiter;

public FirebaseInstallationServiceClient(
@NonNull Context context,
@NonNull Provider<UserAgentPublisher> publisher,
@NonNull Provider<HeartBeatInfo> heartbeatInfo) {
@NonNull Context context, @NonNull Provider<HeartBeatController> heartBeatProvider) {
this.context = context;
this.userAgentPublisher = publisher;
this.heartbeatInfo = heartbeatInfo;
this.heartBeatProvider = heartBeatProvider;
this.requestLimiter = new RequestLimiter();
}

Expand Down Expand Up @@ -485,14 +480,16 @@ private HttpURLConnection openHttpURLConnection(URL url, String apiKey)
httpURLConnection.addRequestProperty(CONTENT_ENCODING_HEADER_KEY, GZIP_CONTENT_ENCODING);
httpURLConnection.addRequestProperty(CACHE_CONTROL_HEADER_KEY, CACHE_CONTROL_DIRECTIVE);
httpURLConnection.addRequestProperty(X_ANDROID_PACKAGE_HEADER_KEY, context.getPackageName());
if ((heartbeatInfo.get() != null) && (userAgentPublisher.get() != null)) {
HeartBeat heartbeat =
heartbeatInfo.get().getHeartBeatCode(FIREBASE_INSTALLATIONS_ID_HEARTBEAT_TAG);
if (heartbeat != HeartBeat.NONE) {
httpURLConnection.addRequestProperty(
USER_AGENT_HEADER, userAgentPublisher.get().getUserAgent());
Copy link

@yoyomyo yoyomyo Dec 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No more userAgent? Why is that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is included in the HEARTBEAT_HEADER itself now. So we don't require two keys. Basically the HEARTBEAT_HEADER is the base64 encoding of a dictionary with userAgent as the key and the set of dates when firebase was used with that useragent string as the value. More information on this can be found at go/firebaseandroid-heartbeat

HeartBeatController heartBeatController = heartBeatProvider.get();
if (heartBeatController != null) {
try {
httpURLConnection.addRequestProperty(
HEART_BEAT_HEADER, Integer.toString(heartbeat.getCode()));
HEART_BEAT_HEADER, Tasks.await(heartBeatController.getHeartBeatsHeader()));
} catch (ExecutionException e) {
Log.w(TAG, "Failed to get heartbeats header", e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
Log.w(TAG, "Failed to get heartbeats header", e);
}
}
httpURLConnection.addRequestProperty(X_ANDROID_CERT_HEADER_KEY, getFingerprintHashForPackage());
Expand Down