Skip to content

Commit a48b095

Browse files
authored
add build number to remote config (#2380)
1 parent 1c62992 commit a48b095

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

firebase-config/src/main/java/com/google/firebase/remoteconfig/RemoteConfigConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public final class RemoteConfigConstants {
4444
RequestFieldKey.LANGUAGE_CODE,
4545
RequestFieldKey.PLATFORM_VERSION,
4646
RequestFieldKey.TIME_ZONE,
47+
RequestFieldKey.APP_BUILD,
4748
RequestFieldKey.APP_VERSION,
4849
RequestFieldKey.PACKAGE_NAME,
4950
RequestFieldKey.SDK_VERSION,
@@ -59,6 +60,7 @@ public final class RemoteConfigConstants {
5960
String PLATFORM_VERSION = "platformVersion";
6061
String TIME_ZONE = "timeZone";
6162
String APP_VERSION = "appVersion";
63+
String APP_BUILD = "appBuild";
6264
String PACKAGE_NAME = "packageName";
6365
String SDK_VERSION = "sdkVersion";
6466
String ANALYTICS_USER_PROPERTIES = "analyticsUserProperties";

firebase-config/src/main/java/com/google/firebase/remoteconfig/internal/ConfigFetchHttpClient.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import static com.google.firebase.remoteconfig.FirebaseRemoteConfig.TAG;
1818
import static com.google.firebase.remoteconfig.RemoteConfigConstants.FETCH_REGEX_URL;
1919
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.ANALYTICS_USER_PROPERTIES;
20+
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.APP_BUILD;
2021
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.APP_ID;
2122
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.APP_VERSION;
2223
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.COUNTRY_CODE;
@@ -41,6 +42,7 @@
4142
import android.util.Log;
4243
import androidx.annotation.Keep;
4344
import androidx.annotation.VisibleForTesting;
45+
import androidx.core.content.pm.PackageInfoCompat;
4446
import com.google.android.gms.common.util.AndroidUtilsLight;
4547
import com.google.android.gms.common.util.Hex;
4648
import com.google.firebase.remoteconfig.BuildConfig;
@@ -322,9 +324,11 @@ private JSONObject createFetchRequestBody(
322324
context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
323325
if (packageInfo != null) {
324326
requestBodyMap.put(APP_VERSION, packageInfo.versionName);
327+
requestBodyMap.put(
328+
APP_BUILD, Long.toString(PackageInfoCompat.getLongVersionCode(packageInfo)));
325329
}
326330
} catch (NameNotFoundException e) {
327-
// Leave app version blank if package cannot be found.
331+
// Leave app version and build number blank if package cannot be found.
328332
}
329333

330334
requestBodyMap.put(PACKAGE_NAME, context.getPackageName());

firebase-config/src/test/java/com/google/firebase/remoteconfig/internal/ConfigFetchHttpClientTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
import static com.google.firebase.remoteconfig.RemoteConfigConstants.ExperimentDescriptionFieldKey.VARIANT_ID;
2121
import static com.google.firebase.remoteconfig.RemoteConfigConstants.FETCH_REGEX_URL;
2222
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.ANALYTICS_USER_PROPERTIES;
23+
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.APP_BUILD;
2324
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.APP_ID;
25+
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.APP_VERSION;
2426
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.COUNTRY_CODE;
2527
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.INSTANCE_ID;
2628
import static com.google.firebase.remoteconfig.RemoteConfigConstants.RequestFieldKey.INSTANCE_ID_TOKEN;
@@ -36,6 +38,7 @@
3638
import static org.mockito.MockitoAnnotations.initMocks;
3739

3840
import android.content.Context;
41+
import android.content.pm.PackageInfo;
3942
import android.os.Build;
4043
import com.google.android.gms.common.util.MockClock;
4144
import com.google.common.base.Charsets;
@@ -205,6 +208,11 @@ public void fetch_setsAllElementsOfRequestBody_sendsRequestBodyToServer() throws
205208
assertThat(requestBody.get(LANGUAGE_CODE)).isEqualTo(locale.toLanguageTag());
206209
assertThat(requestBody.getInt(PLATFORM_VERSION)).isEqualTo(android.os.Build.VERSION.SDK_INT);
207210
assertThat(requestBody.get(TIME_ZONE)).isEqualTo(TimeZone.getDefault().getID());
211+
PackageInfo packageInfo =
212+
context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
213+
assertThat(requestBody.get(APP_VERSION)).isEqualTo(packageInfo.versionName);
214+
assertThat(requestBody.get(APP_BUILD))
215+
.isEqualTo(Long.toString(packageInfo.getLongVersionCode()));
208216
assertThat(requestBody.get(PACKAGE_NAME)).isEqualTo(context.getPackageName());
209217
assertThat(requestBody.get(SDK_VERSION)).isEqualTo(BuildConfig.VERSION_NAME);
210218
assertThat(requestBody.getJSONObject(ANALYTICS_USER_PROPERTIES).toString())

0 commit comments

Comments
 (0)