Skip to content

Commit 4e76e7a

Browse files
committed
Merge branch 'master' into wuandy/OverlayRelease
# Conflicts: # firebase-firestore/CHANGELOG.md # firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteSchema.java
2 parents 1649407 + 9466242 commit 4e76e7a

File tree

38 files changed

+371
-493
lines changed

38 files changed

+371
-493
lines changed

.github/workflows/update-cpp-sdk-on-release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,5 @@ jobs:
7171

7272
- name: Trigger firebase-cpp-sdk update
7373
run: |
74+
pip install -r scripts/gha/requirements.txt
7475
python scripts/gha/trigger_workflow.py -t ${{ steps.generate-token.outputs.token }} -w update-dependencies.yml -p updateAndroid 1 -p updateiOS 0 -p comment "[Triggered]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID) by [firebase-android-sdk $(date '+%b %d') release]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/commit/${{ github.sha }})." -s 10 -A

buildSrc/src/main/java/com/google/firebase/gradle/bomgenerator/tagging/GitClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private void configureSshCommand() {
9999
+ " -o IdentitiesOnly=yes"
100100
+ " -o UserKnownHostsFile=/dev/null"
101101
+ " -o StrictHostKeyChecking=no";
102-
String command = String.format("git config core.sshCommand %s", ssh);
102+
String command = String.format("git config core.sshCommand \"%s\"", ssh);
103103
executor.execute(command, handler);
104104
}
105105
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package com.google.firebase.app.distribution.internal;
15+
package com.google.firebase.app.distribution;
1616

1717
import androidx.annotation.NonNull;
1818
import androidx.annotation.Nullable;
1919
import com.google.auto.value.AutoValue;
20-
import com.google.firebase.app.distribution.BinaryType;
2120

2221
/**
2322
* This class represents the AppDistributionRelease object returned by the App Distribution backend

firebase-app-distribution/src/main/java/com/google/firebase/app/distribution/CheckForNewReleaseClient.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
package com.google.firebase.app.distribution;
1616

17-
import static com.google.firebase.app.distribution.internal.ReleaseIdentificationUtils.calculateApkHash;
17+
import static com.google.firebase.app.distribution.ReleaseIdentificationUtils.calculateApkHash;
1818

1919
import android.content.Context;
2020
import android.content.pm.PackageInfo;
@@ -25,8 +25,6 @@
2525
import com.google.android.gms.tasks.Task;
2626
import com.google.android.gms.tasks.Tasks;
2727
import com.google.firebase.FirebaseApp;
28-
import com.google.firebase.app.distribution.internal.AppDistributionReleaseInternal;
29-
import com.google.firebase.app.distribution.internal.ReleaseIdentificationUtils;
3028
import com.google.firebase.installations.FirebaseInstallationsApi;
3129
import com.google.firebase.installations.InstallationTokenResult;
3230
import java.io.File;
@@ -42,8 +40,8 @@ class CheckForNewReleaseClient {
4240
private final FirebaseApp firebaseApp;
4341
private final FirebaseAppDistributionTesterApiClient firebaseAppDistributionTesterApiClient;
4442
private final FirebaseInstallationsApi firebaseInstallationsApi;
43+
// Maintain an in-memory mapping from source file to APK hash to avoid re-calculating the hash
4544
private static final ConcurrentMap<String, String> cachedApkHashes = new ConcurrentHashMap<>();
46-
private final ReleaseIdentifierStorage releaseIdentifierStorage;
4745

4846
Task<AppDistributionReleaseInternal> cachedCheckForNewRelease = null;
4947
private final Executor checkForNewReleaseExecutor;
@@ -56,20 +54,16 @@ class CheckForNewReleaseClient {
5654
this.firebaseAppDistributionTesterApiClient = firebaseAppDistributionTesterApiClient;
5755
this.firebaseInstallationsApi = firebaseInstallationsApi;
5856
this.checkForNewReleaseExecutor = Executors.newSingleThreadExecutor();
59-
this.releaseIdentifierStorage =
60-
new ReleaseIdentifierStorage(firebaseApp.getApplicationContext());
6157
}
6258

6359
CheckForNewReleaseClient(
6460
@NonNull FirebaseApp firebaseApp,
6561
@NonNull FirebaseAppDistributionTesterApiClient firebaseAppDistributionTesterApiClient,
6662
@NonNull FirebaseInstallationsApi firebaseInstallationsApi,
67-
@NonNull ReleaseIdentifierStorage releaseIdentifierStorage,
6863
@NonNull Executor executor) {
6964
this.firebaseApp = firebaseApp;
7065
this.firebaseAppDistributionTesterApiClient = firebaseAppDistributionTesterApiClient;
7166
this.firebaseInstallationsApi = firebaseInstallationsApi;
72-
this.releaseIdentifierStorage = releaseIdentifierStorage;
7367
this.checkForNewReleaseExecutor = executor;
7468
}
7569

@@ -160,7 +154,8 @@ private boolean isNewerBuildVersion(AppDistributionReleaseInternal newRelease)
160154
}
161155

162156
@VisibleForTesting
163-
boolean isSameAsInstalledRelease(AppDistributionReleaseInternal newRelease) {
157+
boolean isSameAsInstalledRelease(AppDistributionReleaseInternal newRelease)
158+
throws FirebaseAppDistributionException {
164159
if (newRelease.getBinaryType().equals(BinaryType.APK)) {
165160
return hasSameHashAsInstalledRelease(newRelease);
166161
}
@@ -203,7 +198,8 @@ String extractApkHash(PackageInfo packageInfo) {
203198
return cachedApkHashes.get(key);
204199
}
205200

206-
private boolean hasSameHashAsInstalledRelease(AppDistributionReleaseInternal newRelease) {
201+
private boolean hasSameHashAsInstalledRelease(AppDistributionReleaseInternal newRelease)
202+
throws FirebaseAppDistributionException {
207203
try {
208204
Context context = firebaseApp.getApplicationContext();
209205
PackageInfo metadataPackageInfo =
@@ -213,12 +209,9 @@ private boolean hasSameHashAsInstalledRelease(AppDistributionReleaseInternal new
213209
String installedReleaseApkHash = extractApkHash(metadataPackageInfo);
214210

215211
if (installedReleaseApkHash.isEmpty() || newRelease.getApkHash().isEmpty()) {
216-
// We don't have enough information about the APK hashes. Fallback to the external codehash.
217-
// TODO: Consider removing this when all returned releases have the efficient ApkHash
218-
String externalCodeHash =
219-
releaseIdentifierStorage.getExternalCodeHash(installedReleaseApkHash);
220-
LogWrapper.getInstance().v(TAG + "Defaulting to external codehash " + externalCodeHash);
221-
return externalCodeHash != null && externalCodeHash.equals(newRelease.getCodeHash());
212+
LogWrapper.getInstance().e(TAG + "Missing APK hash.");
213+
throw new FirebaseAppDistributionException(
214+
Constants.ErrorMessages.UNKNOWN_ERROR, FirebaseAppDistributionException.Status.UNKNOWN);
222215
}
223216
// If the hash of the zipped APK for the retrieved newRelease is equal to the stored hash
224217
// of the installed release, then they are the same release.

firebase-app-distribution/src/main/java/com/google/firebase/app/distribution/FirebaseAppDistribution.java

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package com.google.firebase.app.distribution;
1616

1717
import static com.google.firebase.app.distribution.FirebaseAppDistributionException.Status.AUTHENTICATION_FAILURE;
18+
import static com.google.firebase.app.distribution.FirebaseAppDistributionException.Status.UPDATE_NOT_AVAILABLE;
1819
import static com.google.firebase.app.distribution.TaskUtils.safeSetTaskException;
1920
import static com.google.firebase.app.distribution.TaskUtils.safeSetTaskResult;
2021

@@ -31,8 +32,6 @@
3132
import com.google.firebase.FirebaseApp;
3233
import com.google.firebase.app.distribution.Constants.ErrorMessages;
3334
import com.google.firebase.app.distribution.FirebaseAppDistributionException.Status;
34-
import com.google.firebase.app.distribution.internal.AppDistributionReleaseInternal;
35-
import com.google.firebase.app.distribution.internal.FirebaseAppDistributionLifecycleNotifier;
3635
import com.google.firebase.installations.FirebaseInstallationsApi;
3736

3837
public class FirebaseAppDistribution {
@@ -41,8 +40,9 @@ public class FirebaseAppDistribution {
4140
private final FirebaseApp firebaseApp;
4241
private final TesterSignInClient testerSignInClient;
4342
private final CheckForNewReleaseClient checkForNewReleaseClient;
44-
private final UpdateAppClient updateAppClient;
4543
private final FirebaseAppDistributionLifecycleNotifier lifecycleNotifier;
44+
private final UpdateApkClient updateApkClient;
45+
private final UpdateAabClient updateAabClient;
4646
private final SignInStorage signInStorage;
4747

4848
private final Object updateIfNewReleaseTaskLock = new Object();
@@ -65,13 +65,15 @@ public class FirebaseAppDistribution {
6565
@NonNull FirebaseApp firebaseApp,
6666
@NonNull TesterSignInClient testerSignInClient,
6767
@NonNull CheckForNewReleaseClient checkForNewReleaseClient,
68-
@NonNull UpdateAppClient updateAppClient,
68+
@NonNull UpdateApkClient updateApkClient,
69+
@NonNull UpdateAabClient updateAabClient,
6970
@NonNull SignInStorage signInStorage,
7071
@NonNull FirebaseAppDistributionLifecycleNotifier lifecycleNotifier) {
7172
this.firebaseApp = firebaseApp;
7273
this.testerSignInClient = testerSignInClient;
7374
this.checkForNewReleaseClient = checkForNewReleaseClient;
74-
this.updateAppClient = updateAppClient;
75+
this.updateApkClient = updateApkClient;
76+
this.updateAabClient = updateAabClient;
7577
this.signInStorage = signInStorage;
7678
this.lifecycleNotifier = lifecycleNotifier;
7779
lifecycleNotifier.addOnActivityDestroyedListener(this::onActivityDestroyed);
@@ -88,7 +90,8 @@ public FirebaseAppDistribution(
8890
new TesterSignInClient(firebaseApp, firebaseInstallationsApi, signInStorage),
8991
new CheckForNewReleaseClient(
9092
firebaseApp, new FirebaseAppDistributionTesterApiClient(), firebaseInstallationsApi),
91-
new UpdateAppClient(firebaseApp),
93+
new UpdateApkClient(firebaseApp, new InstallApkClient()),
94+
new UpdateAabClient(),
9295
signInStorage,
9396
lifecycleNotifier);
9497
}
@@ -240,9 +243,26 @@ private UpdateTask updateApp(boolean showDownloadInNotificationManager) {
240243
Constants.ErrorMessages.AUTHENTICATION_ERROR, AUTHENTICATION_FAILURE));
241244
return updateTask;
242245
}
243-
244246
synchronized (cachedNewReleaseLock) {
245-
return this.updateAppClient.updateApp(cachedNewRelease, showDownloadInNotificationManager);
247+
if (cachedNewRelease == null) {
248+
LogWrapper.getInstance().v("New release not found.");
249+
return getErrorUpdateTask(
250+
new FirebaseAppDistributionException(
251+
Constants.ErrorMessages.NOT_FOUND_ERROR, UPDATE_NOT_AVAILABLE));
252+
}
253+
if (cachedNewRelease.getDownloadUrl() == null) {
254+
LogWrapper.getInstance().v("Download failed to execute");
255+
return getErrorUpdateTask(
256+
new FirebaseAppDistributionException(
257+
Constants.ErrorMessages.DOWNLOAD_URL_NOT_FOUND,
258+
FirebaseAppDistributionException.Status.DOWNLOAD_FAILURE));
259+
}
260+
261+
if (cachedNewRelease.getBinaryType() == BinaryType.AAB) {
262+
return this.updateAabClient.updateAab(cachedNewRelease);
263+
} else {
264+
return this.updateApkClient.updateApk(cachedNewRelease, showDownloadInNotificationManager);
265+
}
246266
}
247267
}
248268

@@ -383,4 +403,10 @@ private void dismissUpdateDialog() {
383403
updateDialogShown = false;
384404
}
385405
}
406+
407+
private UpdateTask getErrorUpdateTask(Exception e) {
408+
UpdateTaskImpl updateTask = new UpdateTaskImpl();
409+
updateTask.setException(e);
410+
return updateTask;
411+
}
386412
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package com.google.firebase.app.distribution.internal;
15+
package com.google.firebase.app.distribution;
1616

1717
import android.app.Activity;
1818
import android.app.Application;

firebase-app-distribution/src/main/java/com/google/firebase/app/distribution/FirebaseAppDistributionRegistrar.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import androidx.annotation.Keep;
1919
import androidx.annotation.NonNull;
2020
import com.google.firebase.FirebaseApp;
21-
import com.google.firebase.app.distribution.internal.FirebaseAppDistributionLifecycleNotifier;
2221
import com.google.firebase.components.Component;
2322
import com.google.firebase.components.ComponentContainer;
2423
import com.google.firebase.components.ComponentRegistrar;

firebase-app-distribution/src/main/java/com/google/firebase/app/distribution/FirebaseAppDistributionTesterApiClient.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import androidx.annotation.NonNull;
2323
import com.google.android.gms.common.util.AndroidUtilsLight;
2424
import com.google.android.gms.common.util.Hex;
25-
import com.google.firebase.app.distribution.internal.AppDistributionReleaseInternal;
2625
import java.io.BufferedInputStream;
2726
import java.io.ByteArrayOutputStream;
2827
import java.io.IOException;

firebase-app-distribution/src/main/java/com/google/firebase/app/distribution/InstallApkClient.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import androidx.annotation.Nullable;
2323
import com.google.android.gms.tasks.Task;
2424
import com.google.android.gms.tasks.TaskCompletionSource;
25-
import com.google.firebase.app.distribution.internal.FirebaseAppDistributionLifecycleNotifier;
2625

2726
class InstallApkClient {
2827
private static final String TAG = "ApkInstallClient:";
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package com.google.firebase.app.distribution.internal;
15+
package com.google.firebase.app.distribution;
1616

1717
import android.content.Context;
1818
import android.content.pm.PackageInfo;
1919
import android.content.pm.PackageManager;
2020
import androidx.annotation.NonNull;
2121
import androidx.annotation.Nullable;
22-
import com.google.firebase.app.distribution.LogWrapper;
2322
import java.io.File;
2423
import java.io.IOException;
2524
import java.nio.ByteBuffer;

firebase-app-distribution/src/main/java/com/google/firebase/app/distribution/ReleaseIdentifierStorage.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

firebase-app-distribution/src/main/java/com/google/firebase/app/distribution/ReleaseUtils.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
package com.google.firebase.app.distribution;
1616

17-
import com.google.firebase.app.distribution.internal.AppDistributionReleaseInternal;
18-
1917
class ReleaseUtils {
2018
static AppDistributionRelease convertToAppDistributionRelease(
2119
AppDistributionReleaseInternal internalRelease) {

firebase-app-distribution/src/main/java/com/google/firebase/app/distribution/TesterSignInClient.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import com.google.android.gms.tasks.Tasks;
3838
import com.google.firebase.FirebaseApp;
3939
import com.google.firebase.app.distribution.Constants.ErrorMessages;
40-
import com.google.firebase.app.distribution.internal.FirebaseAppDistributionLifecycleNotifier;
4140
import com.google.firebase.installations.FirebaseInstallationsApi;
4241
import java.util.List;
4342

firebase-app-distribution/src/main/java/com/google/firebase/app/distribution/UpdateAabClient.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import androidx.annotation.GuardedBy;
2424
import androidx.annotation.NonNull;
2525
import androidx.annotation.VisibleForTesting;
26-
import com.google.firebase.app.distribution.internal.AppDistributionReleaseInternal;
27-
import com.google.firebase.app.distribution.internal.FirebaseAppDistributionLifecycleNotifier;
2826
import java.io.IOException;
2927
import java.net.URL;
3028
import java.util.concurrent.Executor;

firebase-app-distribution/src/main/java/com/google/firebase/app/distribution/UpdateApkClient.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import static com.google.firebase.app.distribution.FirebaseAppDistributionException.Status.NETWORK_FAILURE;
1818
import static com.google.firebase.app.distribution.TaskUtils.safeSetTaskException;
1919
import static com.google.firebase.app.distribution.TaskUtils.safeSetTaskResult;
20-
import static com.google.firebase.app.distribution.internal.ReleaseIdentificationUtils.calculateApkHash;
2120

2221
import android.content.Context;
2322
import androidx.annotation.GuardedBy;
@@ -26,7 +25,6 @@
2625
import com.google.android.gms.tasks.Task;
2726
import com.google.android.gms.tasks.TaskCompletionSource;
2827
import com.google.firebase.FirebaseApp;
29-
import com.google.firebase.app.distribution.internal.AppDistributionReleaseInternal;
3028
import java.io.BufferedOutputStream;
3129
import java.io.File;
3230
import java.io.IOException;
@@ -52,8 +50,6 @@ class UpdateApkClient {
5250
@GuardedBy("updateTaskLock")
5351
private UpdateTaskImpl cachedUpdateTask;
5452

55-
private final ReleaseIdentifierStorage releaseIdentifierStorage;
56-
5753
private final Object updateTaskLock = new Object();
5854

5955
public UpdateApkClient(
@@ -65,8 +61,6 @@ public UpdateApkClient(
6561
@NonNull Executor downloadExecutor,
6662
@NonNull FirebaseApp firebaseApp,
6763
@NonNull InstallApkClient installApkClient) {
68-
this.releaseIdentifierStorage =
69-
new ReleaseIdentifierStorage(firebaseApp.getApplicationContext());
7064
this.appDistributionNotificationsManager =
7165
new FirebaseAppDistributionNotificationsManager(firebaseApp);
7266
this.downloadExecutor = downloadExecutor;
@@ -251,14 +245,6 @@ private void downloadToDisk(
251245
FirebaseAppDistributionException.Status.DOWNLOAD_FAILURE));
252246
}
253247

254-
File downloadedFile = new File(firebaseApp.getApplicationContext().getFilesDir(), fileName);
255-
256-
String internalCodeHash = calculateApkHash(downloadedFile);
257-
258-
if (internalCodeHash != null) {
259-
releaseIdentifierStorage.setCodeHashMap(internalCodeHash, newRelease);
260-
}
261-
262248
// completion
263249
postUpdateProgress(
264250
totalSize, totalSize, UpdateStatus.DOWNLOADED, showDownloadNotificationManager);

0 commit comments

Comments
 (0)