Skip to content

Commit 93b66e5

Browse files
Merge
2 parents f6f3664 + a3a03b1 commit 93b66e5

File tree

46 files changed

+314
-464
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+314
-464
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

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class CheckForNewReleaseClient {
4040
private final FirebaseApp firebaseApp;
4141
private final FirebaseAppDistributionTesterApiClient firebaseAppDistributionTesterApiClient;
4242
private final FirebaseInstallationsApi firebaseInstallationsApi;
43+
// Maintain an in-memory mapping from source file to APK hash to avoid re-calculating the hash
4344
private static final ConcurrentMap<String, String> cachedApkHashes = new ConcurrentHashMap<>();
44-
private final ReleaseIdentifierStorage releaseIdentifierStorage;
4545

4646
Task<AppDistributionReleaseInternal> cachedCheckForNewRelease = null;
4747
private final Executor checkForNewReleaseExecutor;
@@ -54,20 +54,16 @@ class CheckForNewReleaseClient {
5454
this.firebaseAppDistributionTesterApiClient = firebaseAppDistributionTesterApiClient;
5555
this.firebaseInstallationsApi = firebaseInstallationsApi;
5656
this.checkForNewReleaseExecutor = Executors.newSingleThreadExecutor();
57-
this.releaseIdentifierStorage =
58-
new ReleaseIdentifierStorage(firebaseApp.getApplicationContext());
5957
}
6058

6159
CheckForNewReleaseClient(
6260
@NonNull FirebaseApp firebaseApp,
6361
@NonNull FirebaseAppDistributionTesterApiClient firebaseAppDistributionTesterApiClient,
6462
@NonNull FirebaseInstallationsApi firebaseInstallationsApi,
65-
@NonNull ReleaseIdentifierStorage releaseIdentifierStorage,
6663
@NonNull Executor executor) {
6764
this.firebaseApp = firebaseApp;
6865
this.firebaseAppDistributionTesterApiClient = firebaseAppDistributionTesterApiClient;
6966
this.firebaseInstallationsApi = firebaseInstallationsApi;
70-
this.releaseIdentifierStorage = releaseIdentifierStorage;
7167
this.checkForNewReleaseExecutor = executor;
7268
}
7369

@@ -158,7 +154,8 @@ private boolean isNewerBuildVersion(AppDistributionReleaseInternal newRelease)
158154
}
159155

160156
@VisibleForTesting
161-
boolean isSameAsInstalledRelease(AppDistributionReleaseInternal newRelease) {
157+
boolean isSameAsInstalledRelease(AppDistributionReleaseInternal newRelease)
158+
throws FirebaseAppDistributionException {
162159
if (newRelease.getBinaryType().equals(BinaryType.APK)) {
163160
return hasSameHashAsInstalledRelease(newRelease);
164161
}
@@ -201,7 +198,8 @@ String extractApkHash(PackageInfo packageInfo) {
201198
return cachedApkHashes.get(key);
202199
}
203200

204-
private boolean hasSameHashAsInstalledRelease(AppDistributionReleaseInternal newRelease) {
201+
private boolean hasSameHashAsInstalledRelease(AppDistributionReleaseInternal newRelease)
202+
throws FirebaseAppDistributionException {
205203
try {
206204
Context context = firebaseApp.getApplicationContext();
207205
PackageInfo metadataPackageInfo =
@@ -211,12 +209,9 @@ private boolean hasSameHashAsInstalledRelease(AppDistributionReleaseInternal new
211209
String installedReleaseApkHash = extractApkHash(metadataPackageInfo);
212210

213211
if (installedReleaseApkHash.isEmpty() || newRelease.getApkHash().isEmpty()) {
214-
// We don't have enough information about the APK hashes. Fallback to the external codehash.
215-
// TODO: Consider removing this when all returned releases have the efficient ApkHash
216-
String externalCodeHash =
217-
releaseIdentifierStorage.getExternalCodeHash(installedReleaseApkHash);
218-
LogWrapper.getInstance().v(TAG + "Defaulting to external codehash " + externalCodeHash);
219-
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);
220215
}
221216
// If the hash of the zipped APK for the retrieved newRelease is equal to the stored hash
222217
// of the installed release, then they are the same release.

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

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

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

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

1717
import static com.google.firebase.app.distribution.FirebaseAppDistributionException.Status.NETWORK_FAILURE;
18-
import static com.google.firebase.app.distribution.ReleaseIdentificationUtils.calculateApkHash;
1918
import static com.google.firebase.app.distribution.TaskUtils.safeSetTaskException;
2019
import static com.google.firebase.app.distribution.TaskUtils.safeSetTaskResult;
2120

@@ -51,8 +50,6 @@ class UpdateApkClient {
5150
@GuardedBy("updateTaskLock")
5251
private UpdateTaskImpl cachedUpdateTask;
5352

54-
private final ReleaseIdentifierStorage releaseIdentifierStorage;
55-
5653
private final Object updateTaskLock = new Object();
5754

5855
public UpdateApkClient(
@@ -64,8 +61,6 @@ public UpdateApkClient(
6461
@NonNull Executor downloadExecutor,
6562
@NonNull FirebaseApp firebaseApp,
6663
@NonNull InstallApkClient installApkClient) {
67-
this.releaseIdentifierStorage =
68-
new ReleaseIdentifierStorage(firebaseApp.getApplicationContext());
6964
this.appDistributionNotificationsManager =
7065
new FirebaseAppDistributionNotificationsManager(firebaseApp);
7166
this.downloadExecutor = downloadExecutor;
@@ -250,14 +245,6 @@ private void downloadToDisk(
250245
FirebaseAppDistributionException.Status.DOWNLOAD_FAILURE));
251246
}
252247

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

firebase-app-distribution/src/test/java/com/google/firebase/app/distribution/CheckForNewReleaseClientTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ public class CheckForNewReleaseClientTest {
7777
@Mock private FirebaseInstallationsApi mockFirebaseInstallations;
7878
@Mock private FirebaseAppDistributionTesterApiClient mockFirebaseAppDistributionTesterApiClient;
7979
@Mock private InstallationTokenResult mockInstallationTokenResult;
80-
@Mock private ReleaseIdentifierStorage mockReleaseIdentifierStorage;
8180

8281
Executor testExecutor = Executors.newSingleThreadExecutor();
8382

@@ -127,7 +126,6 @@ public void setup() {
127126
firebaseApp,
128127
mockFirebaseAppDistributionTesterApiClient,
129128
mockFirebaseInstallations,
130-
mockReleaseIdentifierStorage,
131129
testExecutor));
132130
}
133131

@@ -307,27 +305,29 @@ public void handleNewReleaseFromClient_whenNewReleaseIsSameAsInstalledAab_return
307305
}
308306

309307
@Test
310-
public void iisSameAsInstalledRelease_whenApkHashesEqual_returnsTrue() {
308+
public void iisSameAsInstalledRelease_whenApkHashesEqual_returnsTrue()
309+
throws FirebaseAppDistributionException {
311310
doReturn(CURRENT_APK_HASH).when(checkForNewReleaseClient).extractApkHash(any());
312311
assertTrue(
313312
checkForNewReleaseClient.isSameAsInstalledRelease(getTestInstalledRelease().build()));
314313
}
315314

316315
@Test
317-
public void isSameAsInstalledRelease_whenApkHashesNotEqual_returnsFalse() {
316+
public void isSameAsInstalledRelease_whenApkHashesNotEqual_returnsFalse()
317+
throws FirebaseAppDistributionException {
318318
doReturn(CURRENT_APK_HASH).when(checkForNewReleaseClient).extractApkHash(any());
319319
assertFalse(checkForNewReleaseClient.isSameAsInstalledRelease(getTestNewRelease().build()));
320320
}
321321

322322
@Test
323-
public void isSameAsInstalledRelease_ifApkHashNotPresent_fallsBackToExternalCodeHash() {
323+
public void isSameAsInstalledRelease_ifApkHashNotPresent_throwsError() {
324324
doReturn(CURRENT_APK_HASH).when(checkForNewReleaseClient).extractApkHash(any());
325-
when(mockReleaseIdentifierStorage.getExternalCodeHash(any())).thenReturn(CURRENT_CODEHASH);
326325

327-
assertFalse(
328-
checkForNewReleaseClient.isSameAsInstalledRelease(
329-
getTestNewRelease().setApkHash("").build()));
330-
verify(mockReleaseIdentifierStorage).getExternalCodeHash(CURRENT_APK_HASH);
326+
assertThrows(
327+
FirebaseAppDistributionException.class,
328+
() ->
329+
checkForNewReleaseClient.isSameAsInstalledRelease(
330+
getTestNewRelease().setApkHash("").build()));
331331
}
332332

333333
@Test

firebase-app-distribution/src/test/java/com/google/firebase/app/distribution/UpdateApkClientTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public class UpdateApkClientTest {
7676
Executor testExecutor = Executors.newSingleThreadExecutor();
7777

7878
@Before
79-
public void setup() {
79+
public void setup() throws FirebaseAppDistributionException {
8080

8181
MockitoAnnotations.initMocks(this);
8282

@@ -96,12 +96,11 @@ public void setup() {
9696

9797
this.updateApkClient =
9898
Mockito.spy(new UpdateApkClient(testExecutor, firebaseApp, mockInstallApkClient));
99+
doReturn(mockHttpsUrlConnection).when(updateApkClient).openHttpsUrlConnection(TEST_URL);
99100
}
100101

101102
@Test
102103
public void updateApk_whenDownloadFails_setsNetworkError() throws Exception {
103-
104-
doReturn(mockHttpsUrlConnection).when(updateApkClient).openHttpsUrlConnection(TEST_URL);
105104
// null inputStream causes download failure
106105
when(mockHttpsUrlConnection.getInputStream()).thenReturn(null);
107106
UpdateTaskImpl updateTask = updateApkClient.updateApk(TEST_RELEASE, false);
@@ -211,6 +210,8 @@ public void postProgressUpdate_whenErrorStatus_updatesNotificationsManagerWithEr
211210

212211
@Test
213212
public void updateApp_whenCalledMultipleTimesWithApk_returnsSameUpdateTask() {
213+
doReturn(Tasks.forResult(mockFile)).when(updateApkClient).downloadApk(TEST_RELEASE, false);
214+
214215
UpdateTask updateTask1 = updateApkClient.updateApk(TEST_RELEASE, false);
215216
UpdateTask updateTask2 = updateApkClient.updateApk(TEST_RELEASE, false);
216217

firebase-crashlytics-ndk/src/main/java/com/google/firebase/crashlytics/ndk/CrashlyticsNdkRegistrar.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
package com.google.firebase.crashlytics.ndk;
1616

17-
import static com.google.firebase.crashlytics.internal.DevelopmentPlatformProvider.UNITY_PLATFORM;
18-
1917
import android.content.Context;
2018
import com.google.firebase.components.Component;
2119
import com.google.firebase.components.ComponentContainer;
@@ -43,8 +41,7 @@ private CrashlyticsNativeComponent buildCrashlyticsNdk(ComponentContainer contai
4341
Context context = container.get(Context.class);
4442
// The signal handler is installed immediately for non-Unity apps. For Unity apps, it will
4543
// be installed when the Firebase Unity SDK explicitly calls installSignalHandler().
46-
boolean installHandlerDuringPrepSession =
47-
!UNITY_PLATFORM.equals(new DevelopmentPlatformProvider(context).getDevelopmentPlatform());
44+
boolean installHandlerDuringPrepSession = !DevelopmentPlatformProvider.isUnity(context);
4845
return FirebaseCrashlyticsNdk.create(context, installHandlerDuringPrepSession);
4946
}
5047
}

firebase-crashlytics-ndk/src/main/java/com/google/firebase/crashlytics/ndk/CrashpadController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ public void writeSessionApp(String sessionId, StaticSessionData.AppData appData)
118118
appData.versionName(),
119119
appData.installUuid(),
120120
appData.deliveryMechanism(),
121-
appData.developmentPlatform(),
122-
appData.developmentPlatformVersion());
121+
appData.developmentPlatformProvider().getDevelopmentPlatform(),
122+
appData.developmentPlatformProvider().getDevelopmentPlatformVersion());
123123
writeSessionJsonFile(fileStore, sessionId, json, APP_METADATA_FILE);
124124
}
125125

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
matt says hi

firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/CrashlyticsNativeComponentDeferredProxyTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package com.google.firebase.crashlytics.internal;
1616

1717
import static org.mockito.ArgumentMatchers.eq;
18+
import static org.mockito.Mockito.mock;
1819

1920
import androidx.annotation.NonNull;
2021
import androidx.test.runner.AndroidJUnit4;
@@ -57,7 +58,7 @@ public void whenAvailable(
5758

5859
StaticSessionData.AppData appData =
5960
StaticSessionData.AppData.create(
60-
"appId", "123", "1.2.3", "install_id", 0, "unity", "unityVersion");
61+
"appId", "123", "1.2.3", "install_id", 0, mock(DevelopmentPlatformProvider.class));
6162
StaticSessionData.OsData osData = StaticSessionData.OsData.create("release", "codeName", false);
6263
StaticSessionData.DeviceData deviceData =
6364
StaticSessionData.DeviceData.create(

firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/DevelopmentPlatformProviderTest.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
package com.google.firebase.crashlytics.internal;
1616

17-
import static com.google.firebase.crashlytics.internal.DevelopmentPlatformProvider.UNITY_PLATFORM;
1817
import static org.mockito.ArgumentMatchers.eq;
1918
import static org.mockito.Mockito.doReturn;
2019
import static org.mockito.Mockito.mock;
@@ -27,20 +26,36 @@
2726

2827
public class DevelopmentPlatformProviderTest extends CrashlyticsTestCase {
2928
private static final String PACKAGE_NAME = "package.name";
29+
private static final String UNITY_PLATFORM = "Unity";
3030
private static final String UNITY_VERSION = "2.0.0";
31+
private static final String FLUTTER_PLATFORM = "Flutter";
3132

3233
public void testDevelopmentPlatformInfo_withUnity_returnsPlatformAndVersion() throws Exception {
3334
Context context = createMockContext(/*withUnityResource=*/ true);
3435

36+
assertTrue(DevelopmentPlatformProvider.isUnity(context));
37+
3538
DevelopmentPlatformProvider provider = new DevelopmentPlatformProvider(context);
3639

3740
assertEquals(UNITY_PLATFORM, provider.getDevelopmentPlatform());
3841
assertEquals(UNITY_VERSION, provider.getDevelopmentPlatformVersion());
3942
}
4043

44+
public void testDevelopmentPlatformInfo_withFlutter_returnsPlatformAndNoVersion() {
45+
Context context = getContext(); // has asset in DevelopmentPlatformProvider.FLUTTER_ASSETS_PATH
46+
47+
DevelopmentPlatformProvider provider = new DevelopmentPlatformProvider(context);
48+
49+
assertEquals(FLUTTER_PLATFORM, provider.getDevelopmentPlatform());
50+
assertNull(provider.getDevelopmentPlatformVersion());
51+
assertFalse(DevelopmentPlatformProvider.isUnity(context));
52+
}
53+
4154
public void testDevelopmentPlatformInfo_unknownPlatform_returnsNull() throws Exception {
4255
Context context = createMockContext(/*withUnityResource=*/ false);
4356

57+
assertFalse(DevelopmentPlatformProvider.isUnity(context));
58+
4459
DevelopmentPlatformProvider provider = new DevelopmentPlatformProvider(context);
4560

4661
assertNull(provider.getDevelopmentPlatform());

firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/common/CrashlyticsControllerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.google.firebase.FirebaseApp;
3535
import com.google.firebase.crashlytics.internal.CrashlyticsNativeComponent;
3636
import com.google.firebase.crashlytics.internal.CrashlyticsTestCase;
37+
import com.google.firebase.crashlytics.internal.DevelopmentPlatformProvider;
3738
import com.google.firebase.crashlytics.internal.NativeSessionFileProvider;
3839
import com.google.firebase.crashlytics.internal.analytics.AnalyticsEventLogger;
3940
import com.google.firebase.crashlytics.internal.log.LogFileManager;
@@ -142,8 +143,7 @@ public CrashlyticsController build() {
142143
"packageName",
143144
"versionCode",
144145
"versionName",
145-
/*developmentPlatform=*/ null,
146-
/*developmentPlatformVersion=*/ null);
146+
mock(DevelopmentPlatformProvider.class));
147147

148148
final CrashlyticsController controller =
149149
new CrashlyticsController(

firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/common/CrashlyticsCoreInitializationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.google.firebase.crashlytics.internal.CrashlyticsNativeComponent;
3131
import com.google.firebase.crashlytics.internal.CrashlyticsNativeComponentDeferredProxy;
3232
import com.google.firebase.crashlytics.internal.CrashlyticsTestCase;
33+
import com.google.firebase.crashlytics.internal.DevelopmentPlatformProvider;
3334
import com.google.firebase.crashlytics.internal.analytics.UnavailableAnalyticsEventLogger;
3435
import com.google.firebase.crashlytics.internal.breadcrumbs.DisabledBreadcrumbSource;
3536
import com.google.firebase.crashlytics.internal.persistence.FileStore;
@@ -263,8 +264,7 @@ private void setupAppData(String buildId) {
263264
"packageName",
264265
"versionCode",
265266
"versionName",
266-
"Unity",
267-
"1.0");
267+
mock(DevelopmentPlatformProvider.class));
268268
}
269269

270270
private void setupResource(Integer resId, String type, String name, String value) {

firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/common/CrashlyticsCoreTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.google.firebase.crashlytics.internal.CrashlyticsNativeComponent;
3333
import com.google.firebase.crashlytics.internal.CrashlyticsNativeComponentDeferredProxy;
3434
import com.google.firebase.crashlytics.internal.CrashlyticsTestCase;
35+
import com.google.firebase.crashlytics.internal.DevelopmentPlatformProvider;
3536
import com.google.firebase.crashlytics.internal.analytics.UnavailableAnalyticsEventLogger;
3637
import com.google.firebase.crashlytics.internal.breadcrumbs.BreadcrumbHandler;
3738
import com.google.firebase.crashlytics.internal.breadcrumbs.BreadcrumbSource;
@@ -343,8 +344,7 @@ private Task<CrashlyticsCore> startCoreAsync(CrashlyticsCore crashlyticsCore) {
343344
"packageName",
344345
"versionCode",
345346
"versionName",
346-
"Unity",
347-
"1.0");
347+
mock(DevelopmentPlatformProvider.class));
348348

349349
crashlyticsCore.onPreExecute(appData, mockSettingsController);
350350

0 commit comments

Comments
 (0)