Skip to content

Add build number to Remote Config #2380

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
Feb 9, 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 @@ -44,6 +44,7 @@ public final class RemoteConfigConstants {
RequestFieldKey.LANGUAGE_CODE,
RequestFieldKey.PLATFORM_VERSION,
RequestFieldKey.TIME_ZONE,
RequestFieldKey.APP_BUILD,
RequestFieldKey.APP_VERSION,
RequestFieldKey.PACKAGE_NAME,
RequestFieldKey.SDK_VERSION,
Expand All @@ -59,6 +60,7 @@ public final class RemoteConfigConstants {
String PLATFORM_VERSION = "platformVersion";
String TIME_ZONE = "timeZone";
String APP_VERSION = "appVersion";
String APP_BUILD = "appBuild";
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like a consistent pattern that the iOS constants use underscores and Android uses camel case

String PACKAGE_NAME = "packageName";
String SDK_VERSION = "sdkVersion";
String ANALYTICS_USER_PROPERTIES = "analyticsUserProperties";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static com.google.firebase.remoteconfig.FirebaseRemoteConfig.TAG;
import static com.google.firebase.remoteconfig.RemoteConfigConstants.FETCH_REGEX_URL;
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.ANALYTICS_USER_PROPERTIES;
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.APP_BUILD;
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.APP_ID;
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.APP_VERSION;
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.COUNTRY_CODE;
Expand All @@ -41,6 +42,7 @@
import android.util.Log;
import androidx.annotation.Keep;
import androidx.annotation.VisibleForTesting;
import androidx.core.content.pm.PackageInfoCompat;
import com.google.android.gms.common.util.AndroidUtilsLight;
import com.google.android.gms.common.util.Hex;
import com.google.firebase.remoteconfig.BuildConfig;
Expand Down Expand Up @@ -322,9 +324,11 @@ private JSONObject createFetchRequestBody(
context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
if (packageInfo != null) {
requestBodyMap.put(APP_VERSION, packageInfo.versionName);
requestBodyMap.put(
APP_BUILD, Long.toString(PackageInfoCompat.getLongVersionCode(packageInfo)));
}
} catch (NameNotFoundException e) {
// Leave app version blank if package cannot be found.
// Leave app version and build number blank if package cannot be found.
}

requestBodyMap.put(PACKAGE_NAME, context.getPackageName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import static com.google.firebase.remoteconfig.RemoteConfigConstants.ExperimentDescriptionFieldKey.VARIANT_ID;
import static com.google.firebase.remoteconfig.RemoteConfigConstants.FETCH_REGEX_URL;
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.ANALYTICS_USER_PROPERTIES;
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.APP_BUILD;
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.APP_ID;
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.APP_VERSION;
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.COUNTRY_CODE;
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.INSTANCE_ID;
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.INSTANCE_ID_TOKEN;
Expand All @@ -36,6 +38,7 @@
import static org.mockito.MockitoAnnotations.initMocks;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.os.Build;
import com.google.android.gms.common.util.MockClock;
import com.google.common.base.Charsets;
Expand Down Expand Up @@ -205,6 +208,11 @@ public void fetch_setsAllElementsOfRequestBody_sendsRequestBodyToServer() throws
assertThat(requestBody.get(LANGUAGE_CODE)).isEqualTo(locale.toLanguageTag());
assertThat(requestBody.getInt(PLATFORM_VERSION)).isEqualTo(android.os.Build.VERSION.SDK_INT);
assertThat(requestBody.get(TIME_ZONE)).isEqualTo(TimeZone.getDefault().getID());
PackageInfo packageInfo =
context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
assertThat(requestBody.get(APP_VERSION)).isEqualTo(packageInfo.versionName);
assertThat(requestBody.get(APP_BUILD))
.isEqualTo(Long.toString(packageInfo.getLongVersionCode()));
assertThat(requestBody.get(PACKAGE_NAME)).isEqualTo(context.getPackageName());
assertThat(requestBody.get(SDK_VERSION)).isEqualTo(BuildConfig.VERSION_NAME);
assertThat(requestBody.getJSONObject(ANALYTICS_USER_PROPERTIES).toString())
Expand Down