Skip to content

Commit e9aff7a

Browse files
Merge branch 'master' into fad-remove-unsued-enums
2 parents fd71177 + 486da83 commit e9aff7a

File tree

124 files changed

+3400
-1850
lines changed

Some content is hidden

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

124 files changed

+3400
-1850
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ dependencies:
2222
* `firebase-inappmessaging-ktx`
2323
* `firebase-inappmessaging-display`
2424
* `firebase-inappmessaging-display-ktx`
25+
* `firebase-messaging`
26+
* `firebase-messaging-directboot`
2527
* `firebase-perf`
2628
* `firebase-perf-ktx`
2729
* `firebase-remote-config`

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ buildscript {
1818
ext.kotlinVersion = '1.3.72'
1919
repositories {
2020
google()
21-
jcenter()
2221
mavenCentral()
2322
maven {
2423
url "https://plugins.gradle.org/m2/"
2524
}
2625
maven {
2726
url 'https://storage.googleapis.com/android-ci/mvn/'
2827
}
28+
jcenter()
2929
}
3030

3131
dependencies {
@@ -70,11 +70,11 @@ if(JavaVersion.current() != JavaVersion.VERSION_11){
7070
configure(subprojects) {
7171
repositories {
7272
google()
73-
jcenter()
7473
mavenLocal()
7574
maven {
7675
url 'https://storage.googleapis.com/android-ci/mvn/'
7776
}
77+
jcenter()
7878
}
7979

8080
apply plugin: "org.jlleitschuh.gradle.ktlint"

ci/fireci/fireciplugins/fireperf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def fireperf_e2e_test(target_environment, plugin_repo_dir):
4242

4343
_logger.info('Building fireperf plugin ...')
4444
with chdir(plugin_repo_dir):
45-
build_plugin_task = ':firebase-performance:performance-gradle:publishToMavenLocal'
45+
build_plugin_task = ':firebase-performance:perf-plugin:publishToMavenLocal'
4646
gradle.run(build_plugin_task, gradle.P('publishMode', 'SNAPSHOT'))
4747

4848
version = _find_fireperf_plugin_version()

ci/fireci/fireciplugins/macrobenchmark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ async def _execute_benchmark_tests(self):
184184
args += ['--type', 'instrumentation']
185185
args += ['--app', app_apk_path]
186186
args += ['--test', test_apk_path]
187-
args += ['--device', 'model=flame,version=30,locale=en,orientation=portrait']
187+
args += ['--device', 'model=redfin,version=30,locale=en,orientation=portrait']
188188
args += ['--directories-to-pull', '/sdcard/Download']
189189
args += ['--results-bucket', f'gs://{self.test_results_bucket}']
190190
args += ['--results-dir', self.test_results_dir]

firebase-appdistribution-stub/firebase-appdistribution-stub.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ android {
3939

4040
dependencies {
4141
implementation 'org.jetbrains:annotations:15.0'
42-
implementation project(':firebase-components')
43-
implementation project(':firebase-common')
4442
implementation 'com.google.android.gms:play-services-tasks:17.0.0'
4543

4644
testImplementation 'junit:junit:4.13.2'

firebase-appdistribution/api.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ package com.google.firebase.appdistribution {
3434
enum_constant public static final com.google.firebase.appdistribution.FirebaseAppDistributionException.Status AUTHENTICATION_CANCELED;
3535
enum_constant public static final com.google.firebase.appdistribution.FirebaseAppDistributionException.Status AUTHENTICATION_FAILURE;
3636
enum_constant public static final com.google.firebase.appdistribution.FirebaseAppDistributionException.Status DOWNLOAD_FAILURE;
37+
enum_constant public static final com.google.firebase.appdistribution.FirebaseAppDistributionException.Status HOST_ACTIVITY_INTERRUPTED;
3738
enum_constant public static final com.google.firebase.appdistribution.FirebaseAppDistributionException.Status INSTALLATION_CANCELED;
3839
enum_constant public static final com.google.firebase.appdistribution.FirebaseAppDistributionException.Status INSTALLATION_FAILURE;
3940
enum_constant public static final com.google.firebase.appdistribution.FirebaseAppDistributionException.Status NETWORK_FAILURE;

firebase-appdistribution/ktx/src/androidTest/kotlin/com/google/firebase/app/distribution/ktx/FirebaseAppDistributionTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class FirebaseAppDistributionTests : BaseTestCase() {
7272
}
7373
}
7474

75-
internal const val LIBRARY_NAME: String = "fire-app-distribution-ktx"
75+
internal const val LIBRARY_NAME: String = "fire-appdistribution-ktx"
7676

7777
@RunWith(AndroidJUnit4ClassRunner::class)
7878
class LibraryVersionTest : BaseTestCase() {

firebase-appdistribution/ktx/src/main/kotlin/com/google/firebase/appdistribution/ktx/FirebaseAppDistribution.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import com.google.firebase.platforminfo.LibraryVersionComponent
2727
val Firebase.appDistribution: FirebaseAppDistribution
2828
get() = FirebaseAppDistribution.getInstance()
2929

30-
internal const val LIBRARY_NAME: String = "fire-app-distribution-ktx"
30+
internal const val LIBRARY_NAME: String = "fire-appdistribution-ktx"
3131

3232
/** @suppress */
3333
@Keep

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/AabUpdater.java

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
import static com.google.firebase.appdistribution.FirebaseAppDistributionException.Status.DOWNLOAD_FAILURE;
1818
import static com.google.firebase.appdistribution.FirebaseAppDistributionException.Status.NETWORK_FAILURE;
19+
import static com.google.firebase.appdistribution.TaskUtils.runAsyncInTask;
1920
import static com.google.firebase.appdistribution.TaskUtils.safeSetTaskException;
2021

2122
import android.app.Activity;
22-
import android.content.Context;
2323
import android.content.Intent;
2424
import android.net.Uri;
2525
import androidx.annotation.GuardedBy;
@@ -36,35 +36,34 @@
3636

3737
/** Class that handles updateApp functionality for AABs in {@link FirebaseAppDistribution}. */
3838
class AabUpdater {
39-
private static final String TAG = "UpdateAabClient:";
39+
private static final String TAG = "AabUpdater:";
4040

4141
private final FirebaseAppDistributionLifecycleNotifier lifecycleNotifier;
4242
private final HttpsUrlConnectionFactory httpsUrlConnectionFactory;
4343
private final Executor executor;
4444

45+
private final Object updateAabLock = new Object();
46+
4547
@GuardedBy("updateAabLock")
4648
private UpdateTaskImpl cachedUpdateTask;
4749

4850
@GuardedBy("updateAabLock")
4951
private AppDistributionReleaseInternal aabReleaseInProgress;
5052

51-
private final Object updateAabLock = new Object();
52-
private final Context context;
53+
@GuardedBy("updateAabLock")
54+
private boolean hasBeenSentToPlayForCurrentTask = false;
5355

54-
AabUpdater(@NonNull Context context) {
56+
AabUpdater() {
5557
this(
56-
context,
5758
FirebaseAppDistributionLifecycleNotifier.getInstance(),
5859
new HttpsUrlConnectionFactory(),
5960
Executors.newSingleThreadExecutor());
6061
}
6162

6263
AabUpdater(
63-
@NonNull Context context,
6464
@NonNull FirebaseAppDistributionLifecycleNotifier lifecycleNotifier,
6565
@NonNull HttpsUrlConnectionFactory httpsUrlConnectionFactory,
6666
@NonNull Executor executor) {
67-
this.context = context;
6867
this.lifecycleNotifier = lifecycleNotifier;
6968
this.httpsUrlConnectionFactory = httpsUrlConnectionFactory;
7069
lifecycleNotifier.addOnActivityStartedListener(this::onActivityStarted);
@@ -76,9 +75,13 @@ void onActivityStarted(Activity activity) {
7675
if (activity instanceof SignInResultActivity || activity instanceof InstallActivity) {
7776
return;
7877
}
79-
// If app resumes and aab update task is in progress, assume that installation didn't happen so
80-
// cancel the task
81-
this.tryCancelAabUpdateTask();
78+
// If app resumes and update is in progress, assume that installation didn't happen and cancel
79+
// the task
80+
synchronized (updateAabLock) {
81+
if (awaitingUpdateFromPlay()) {
82+
this.tryCancelAabUpdateTask();
83+
}
84+
}
8285
}
8386

8487
UpdateTaskImpl updateAab(@NonNull AppDistributionReleaseInternal newRelease) {
@@ -89,7 +92,15 @@ UpdateTaskImpl updateAab(@NonNull AppDistributionReleaseInternal newRelease) {
8992

9093
cachedUpdateTask = new UpdateTaskImpl();
9194
aabReleaseInProgress = newRelease;
92-
redirectToPlayForAabUpdate(newRelease.getDownloadUrl());
95+
hasBeenSentToPlayForCurrentTask = false;
96+
97+
// On a background thread, fetch the redirect URL and open it in the Play app
98+
runAsyncInTask(executor, () -> fetchDownloadRedirectUrl(newRelease.getDownloadUrl()))
99+
.onSuccessTask(
100+
redirectUrl ->
101+
lifecycleNotifier.applyToForegroundActivity(
102+
activity -> openRedirectUrlInPlay(redirectUrl, activity)))
103+
.addOnFailureListener(this::setUpdateTaskCompletionError);
93104

94105
return cachedUpdateTask;
95106
}
@@ -138,38 +149,30 @@ private static boolean isRedirectResponse(int responseCode) {
138149
return responseCode >= 300 && responseCode < 400;
139150
}
140151

141-
private void redirectToPlayForAabUpdate(String downloadUrl) {
142-
// The 302 redirect is obtained here to open the play store directly and avoid opening chrome
143-
executor.execute( // Execute the network calls on a background thread
144-
() -> {
145-
String redirectUrl;
146-
try {
147-
redirectUrl = fetchDownloadRedirectUrl(downloadUrl);
148-
} catch (FirebaseAppDistributionException e) {
149-
setUpdateTaskCompletionError(e);
150-
return;
151-
}
152-
153-
Intent updateIntent = new Intent(Intent.ACTION_VIEW);
154-
updateIntent.setData(Uri.parse(redirectUrl));
155-
updateIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
156-
LogWrapper.getInstance().v(TAG + "Redirecting to play");
157-
158-
synchronized (updateAabLock) {
159-
context.startActivity(updateIntent);
160-
cachedUpdateTask.updateProgress(
161-
UpdateProgress.builder()
162-
.setApkBytesDownloaded(-1)
163-
.setApkFileTotalBytes(-1)
164-
.setUpdateStatus(UpdateStatus.REDIRECTED_TO_PLAY)
165-
.build());
166-
}
167-
});
152+
private void openRedirectUrlInPlay(String redirectUrl, Activity hostActivity) {
153+
Intent updateIntent = new Intent(Intent.ACTION_VIEW);
154+
updateIntent.setData(Uri.parse(redirectUrl));
155+
updateIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
156+
LogWrapper.getInstance().v(TAG + "Redirecting to play");
157+
158+
// Launch the intent before the synchronized block to avoid failing to update in the rare
159+
// scenario where the activity moves to the background while we're awaiting the lock.
160+
hostActivity.startActivity(updateIntent);
161+
162+
synchronized (updateAabLock) {
163+
cachedUpdateTask.updateProgress(
164+
UpdateProgress.builder()
165+
.setApkBytesDownloaded(-1)
166+
.setApkFileTotalBytes(-1)
167+
.setUpdateStatus(UpdateStatus.REDIRECTED_TO_PLAY)
168+
.build());
169+
hasBeenSentToPlayForCurrentTask = true;
170+
}
168171
}
169172

170-
private void setUpdateTaskCompletionError(FirebaseAppDistributionException e) {
173+
private void setUpdateTaskCompletionError(Exception e) {
171174
synchronized (updateAabLock) {
172-
safeSetTaskException(cachedUpdateTask, e);
175+
safeSetTaskException(cachedUpdateTask, FirebaseAppDistributionException.wrap(e));
173176
}
174177
}
175178

@@ -183,4 +186,12 @@ void tryCancelAabUpdateTask() {
183186
ReleaseUtils.convertToAppDistributionRelease(aabReleaseInProgress)));
184187
}
185188
}
189+
190+
private boolean awaitingUpdateFromPlay() {
191+
synchronized (updateAabLock) {
192+
return cachedUpdateTask != null
193+
&& !cachedUpdateTask.isComplete()
194+
&& hasBeenSentToPlayForCurrentTask;
195+
}
196+
}
186197
}

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/ApkInstaller.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
/** Class that handles installing APKs in {@link FirebaseAppDistribution}. */
2929
class ApkInstaller {
30-
private static final String TAG = "ApkInstallClient:";
30+
private static final String TAG = "ApkInstaller:";
3131
private final FirebaseAppDistributionLifecycleNotifier lifeCycleNotifier;
3232

3333
@GuardedBy("installTaskLock")

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/ApkUpdater.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
class ApkUpdater {
4545

4646
private static final int UPDATE_INTERVAL_MS = 250;
47-
private static final String TAG = "UpdateApkClient:";
47+
private static final String TAG = "ApkUpdater:";
4848
private static final String REQUEST_METHOD_GET = "GET";
4949
private static final String DEFAULT_APK_FILE_NAME = "downloaded_release.apk";
5050

@@ -113,8 +113,8 @@ UpdateTaskImpl updateApk(
113113

114114
private void installApk(File file, boolean showDownloadNotificationManager) {
115115
lifeCycleNotifier
116-
.getForegroundActivity()
117-
.onSuccessTask(taskExecutor, activity -> apkInstaller.installApk(file.getPath(), activity))
116+
.applyToForegroundActivityTask(
117+
activity -> apkInstaller.installApk(file.getPath(), activity))
118118
.addOnSuccessListener(
119119
taskExecutor,
120120
unused -> {

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/Constants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ static class ErrorMessages {
3737

3838
public static final String DOWNLOAD_URL_NOT_FOUND = "Download URL not found";
3939

40+
public static final String HOST_ACTIVITY_INTERRUPTED =
41+
"Host activity interrupted while dialog was showing";
42+
4043
public static final String APK_INSTALLATION_FAILED =
4144
"The APK failed to install or installation was cancelled";
4245
}

0 commit comments

Comments
 (0)