Skip to content

Commit 6c75d59

Browse files
author
rachaprince
authored
Change logic in check for update so it correctly prompts on new APK releases (#2898)
1 parent 958483c commit 6c75d59

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

firebase-app-distribution/src/main/java/com/google/firebase/appdistribution/CheckForUpdateClient.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ AppDistributionReleaseInternal getLatestReleaseFromClient(
115115
firebaseAppDistributionTesterApiClient.fetchLatestRelease(fid, appId, apiKey, authToken);
116116

117117
if (isNewerBuildVersion(retrievedLatestRelease)
118-
&& !isInstalledRelease(retrievedLatestRelease)) {
118+
|| !isInstalledRelease(retrievedLatestRelease)) {
119119
return retrievedLatestRelease;
120120
} else {
121121
// Return null if retrieved latest release is older or currently installed
@@ -132,13 +132,14 @@ AppDistributionReleaseInternal getLatestReleaseFromClient(
132132
private boolean isNewerBuildVersion(AppDistributionReleaseInternal latestRelease)
133133
throws FirebaseAppDistributionException {
134134
return Long.parseLong(latestRelease.getBuildVersion())
135-
>= getInstalledAppVersionCode(firebaseApp.getApplicationContext());
135+
> getInstalledAppVersionCode(firebaseApp.getApplicationContext());
136136
}
137137

138138
private boolean isInstalledRelease(AppDistributionReleaseInternal latestRelease) {
139139
if (latestRelease.getBinaryType().equals(BinaryType.APK)) {
140-
// TODO(rachelprince): APK codehash verification
141-
return false;
140+
// TODO(rachelprince): APK codehash verification. For now assume
141+
// the release is identical unless the build version is different
142+
return true;
142143
}
143144

144145
if (latestRelease.getIasArtifactId() == null) {

firebase-app-distribution/src/test/java/com/google/firebase/appdistribution/CheckForUpdateClientTest.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public void checkForUpdateTask_whenCalledMultipleTimes_returnsTheSameTask() {
149149
@Test
150150
public void checkForUpdate_succeeds() throws Exception {
151151
when(mockFirebaseAppDistributionTesterApiClient.fetchLatestRelease(any(), any(), any(), any()))
152-
.thenReturn(TEST_RELEASE_CURRENT);
152+
.thenReturn(TEST_RELEASE_NEWER_APK);
153153
when(mockFirebaseInstallations.getId()).thenReturn(Tasks.forResult(TEST_FID_1));
154154
when(mockFirebaseInstallations.getToken(false))
155155
.thenReturn(Tasks.forResult(mockInstallationTokenResult));
@@ -160,7 +160,7 @@ public void checkForUpdate_succeeds() throws Exception {
160160
task.addOnCompleteListener(testExecutor, onCompleteListener);
161161

162162
AppDistributionReleaseInternal appDistributionReleaseInternal = onCompleteListener.await();
163-
assertEquals(TEST_RELEASE_CURRENT, appDistributionReleaseInternal);
163+
assertEquals(TEST_RELEASE_NEWER_APK, appDistributionReleaseInternal);
164164
verify(mockFirebaseInstallations, times(1)).getId();
165165
verify(mockFirebaseInstallations, times(1)).getToken(false);
166166
}
@@ -227,18 +227,11 @@ public void getLatestReleaseFromClient_whenLatestReleaseIsNewerBuildThanInstalle
227227
}
228228

229229
@Test
230-
public void getLatestReleaseFromClient_whenLatestReleaseIsOlderBuildThanInstalled_returnsNull()
230+
public void getLatestReleaseFromClient_whenLatestReleaseIsSameRelease_returnsNull()
231231
throws Exception {
232-
AppDistributionReleaseInternal olderTestRelease =
233-
AppDistributionReleaseInternal.builder()
234-
.setBinaryType(BinaryType.APK)
235-
.setBuildVersion("1")
236-
.setDisplayVersion("1.0")
237-
.setReleaseNotes("Older version.")
238-
.build();
239232
when(mockFirebaseAppDistributionTesterApiClient.fetchLatestRelease(
240233
TEST_FID_1, TEST_APP_ID_1, TEST_API_KEY, TEST_AUTH_TOKEN))
241-
.thenReturn(olderTestRelease);
234+
.thenReturn(TEST_RELEASE_CURRENT);
242235

243236
AppDistributionReleaseInternal release =
244237
checkForUpdateClient.getLatestReleaseFromClient(

0 commit comments

Comments
 (0)