Skip to content

Commit 4dcbe29

Browse files
committed
Merge remote-tracking branch 'origin/master' into OverlayNeverNull
2 parents 2267bca + f103c35 commit 4dcbe29

File tree

7 files changed

+47
-34
lines changed

7 files changed

+47
-34
lines changed

appcheck/firebase-appcheck-debug-testing/firebase-appcheck-debug-testing.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ dependencies {
5252
implementation 'com.google.android.gms:play-services-tasks:18.0.1'
5353
implementation 'androidx.test:core:1.2.0'
5454

55+
javadocClasspath 'com.google.auto.value:auto-value-annotations:1.6.6'
56+
5557
testImplementation 'junit:junit:4.13-beta-2'
5658
testImplementation 'org.mockito:mockito-core:2.25.0'
5759
testImplementation "org.robolectric:robolectric:$robolectricVersion"

appcheck/firebase-appcheck-safetynet/firebase-appcheck-safetynet.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ dependencies {
4949
implementation 'com.google.android.gms:play-services-safetynet:18.0.0'
5050

5151
javadocClasspath 'com.google.auto.value:auto-value-annotations:1.6.6'
52+
javadocClasspath 'org.checkerframework:checker-qual:2.5.2'
5253

5354
testImplementation 'junit:junit:4.13-beta-2'
5455
testImplementation 'org.mockito:mockito-core:2.25.0'

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

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ private void installApk(File file, boolean showDownloadNotificationManager) {
128128
file.length(),
129129
file.length(),
130130
UpdateStatus.INSTALL_FAILED,
131-
showDownloadNotificationManager);
131+
showDownloadNotificationManager,
132+
R.string.install_failed);
132133
setUpdateTaskCompletionErrorWithDefault(
133134
e,
134135
FirebaseAppDistributionException.ErrorMessages.APK_INSTALLATION_FAILED,
@@ -179,7 +180,8 @@ private void makeApkDownloadRequest(
179180
}
180181

181182
long responseLength = connection.getContentLength();
182-
postUpdateProgress(responseLength, 0, UpdateStatus.PENDING, showNotification);
183+
postUpdateProgress(
184+
responseLength, 0, UpdateStatus.PENDING, showNotification, R.string.downloading_app_update);
183185
String fileName = getApkFileName();
184186
LogWrapper.getInstance().v(TAG + "Attempting to download APK to disk");
185187

@@ -188,7 +190,12 @@ private void makeApkDownloadRequest(
188190
File apkFile = context.getFileStreamPath(fileName);
189191
validateJarFile(apkFile, responseLength, showNotification, bytesDownloaded);
190192

191-
postUpdateProgress(responseLength, bytesDownloaded, UpdateStatus.DOWNLOADED, showNotification);
193+
postUpdateProgress(
194+
responseLength,
195+
bytesDownloaded,
196+
UpdateStatus.DOWNLOADED,
197+
showNotification,
198+
R.string.download_completed);
192199
safeSetTaskResult(downloadTaskCompletionSource, apkFile);
193200
}
194201

@@ -220,12 +227,20 @@ private long downloadToDisk(
220227
if (currentTimeMs - lastMsUpdated > UPDATE_INTERVAL_MS) {
221228
lastMsUpdated = currentTimeMs;
222229
postUpdateProgress(
223-
totalSize, bytesDownloaded, UpdateStatus.DOWNLOADING, showNotification);
230+
totalSize,
231+
bytesDownloaded,
232+
UpdateStatus.DOWNLOADING,
233+
showNotification,
234+
R.string.downloading_app_update);
224235
}
225236
}
226237
} catch (IOException e) {
227238
postUpdateProgress(
228-
totalSize, bytesDownloaded, UpdateStatus.DOWNLOAD_FAILED, showNotification);
239+
totalSize,
240+
bytesDownloaded,
241+
UpdateStatus.DOWNLOAD_FAILED,
242+
showNotification,
243+
R.string.download_failed);
229244
throw new FirebaseAppDistributionException("Failed to download APK", DOWNLOAD_FAILURE, e);
230245
}
231246
return bytesDownloaded;
@@ -238,7 +253,11 @@ private void validateJarFile(
238253
new JarFile(apkFile).close();
239254
} catch (IOException e) {
240255
postUpdateProgress(
241-
totalSize, bytesDownloaded, UpdateStatus.DOWNLOAD_FAILED, showNotification);
256+
totalSize,
257+
bytesDownloaded,
258+
UpdateStatus.DOWNLOAD_FAILED,
259+
showNotification,
260+
R.string.download_failed);
242261
throw new FirebaseAppDistributionException(
243262
"Downloaded APK was not a valid JAR file", DOWNLOAD_FAILURE, e);
244263
}
@@ -274,7 +293,11 @@ private void setUpdateTaskCompletionErrorWithDefault(Exception e, String message
274293
}
275294

276295
private void postUpdateProgress(
277-
long totalBytes, long downloadedBytes, UpdateStatus status, boolean showNotification) {
296+
long totalBytes,
297+
long downloadedBytes,
298+
UpdateStatus status,
299+
boolean showNotification,
300+
int stringResourceId) {
278301
synchronized (updateTaskLock) {
279302
cachedUpdateTask.updateProgress(
280303
UpdateProgress.builder()
@@ -284,7 +307,8 @@ private void postUpdateProgress(
284307
.build());
285308
}
286309
if (showNotification) {
287-
appDistributionNotificationsManager.updateNotification(totalBytes, downloadedBytes, status);
310+
appDistributionNotificationsManager.updateNotification(
311+
totalBytes, downloadedBytes, stringResourceId);
288312
}
289313
}
290314
}

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

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ class FirebaseAppDistributionNotificationsManager {
4646
this.appIconSource = appIconSource;
4747
}
4848

49-
void updateNotification(long totalBytes, long downloadedBytes, UpdateStatus status) {
49+
void updateNotification(long totalBytes, long downloadedBytes, int stringResourceId) {
5050
NotificationManager notificationManager = createNotificationManager(context);
5151
NotificationCompat.Builder notificationBuilder =
5252
new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
5353
.setOnlyAlertOnce(true)
5454
.setSmallIcon(appIconSource.getNonAdaptiveIconOrDefault(context))
55-
.setContentTitle(context.getString(getNotificationContentTitleId(status)))
55+
.setContentTitle(context.getString(stringResourceId))
5656
.setProgress(
5757
100,
5858
(int) (((float) downloadedBytes / (float) totalBytes) * 100),
@@ -64,25 +64,6 @@ void updateNotification(long totalBytes, long downloadedBytes, UpdateStatus stat
6464
notificationManager.notify(NOTIFICATION_TAG, /*id =*/ 0, notificationBuilder.build());
6565
}
6666

67-
int getNotificationContentTitleId(UpdateStatus status) {
68-
if (isErrorState(status)) {
69-
return R.string.download_failed;
70-
} else if (status.equals(UpdateStatus.DOWNLOADED)) {
71-
return R.string.download_completed;
72-
} else {
73-
return R.string.downloading_app_update;
74-
}
75-
}
76-
77-
// CHECK THIS LATER
78-
private boolean isErrorState(UpdateStatus status) {
79-
return status.equals(UpdateStatus.DOWNLOAD_FAILED)
80-
|| status.equals(UpdateStatus.INSTALL_FAILED)
81-
|| status.equals(UpdateStatus.INSTALL_CANCELED)
82-
|| status.equals(UpdateStatus.NEW_RELEASE_CHECK_FAILED)
83-
|| status.equals(UpdateStatus.UPDATE_CANCELED);
84-
}
85-
8667
private NotificationManager createNotificationManager(Context context) {
8768
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
8869
NotificationChannel channel =

firebase-appdistribution/src/main/res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
<string name="downloading_app_update">Downloading in-app update...</string>
2626
<string name="download_completed">Download completed</string>
2727
<string name="download_failed">Download failed</string>
28+
<string name="download_pending">Download pending</string>
29+
<string name="install_failed">Install failed</string>
30+
<string name="install_canceled">Install canceled</string>
31+
<string name="update_canceled">Update canceled </string>
2832
<string name="notifications_channel_name">App Distribution App Update Downloads</string>
2933
<string name="notifications_channel_description">Shows download progress of in-app updates from App Distribution SDK</string>
3034
<string name="unknown_sources_dialog_title">Enable Unknown Sources</string>

firebase-appdistribution/src/test/java/com/google/firebase/appdistribution/ApkUpdaterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public void updateApk_whenInstallFailed_setsError() {
196196
assertThat(progressEvents).hasSize(1);
197197
assertThat(progressEvents.get(0).getUpdateStatus()).isEqualTo(UpdateStatus.INSTALL_FAILED);
198198
assertThat(updateTask.isSuccessful()).isFalse();
199-
verify(mockNotificationsManager).updateNotification(1000, 1000, UpdateStatus.INSTALL_FAILED);
199+
verify(mockNotificationsManager).updateNotification(1000, 1000, R.string.install_failed);
200200
}
201201

202202
@Test

firebase-appdistribution/src/test/java/com/google/firebase/appdistribution/FirebaseAppDistributionNotificationsManagerTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void setup() {
5050
@Test
5151
public void updateNotification_withProgress() {
5252
firebaseAppDistributionNotificationsManager.updateNotification(
53-
1000, 900, UpdateStatus.DOWNLOADING);
53+
1000, 900, R.string.downloading_app_update);
5454
assertThat(shadowOf(notificationManager).size()).isEqualTo(1);
5555
Notification notification = shadowOf(notificationManager).getNotification(NOTIFICATION_TAG, 0);
5656
assertThat(shadowOf(notification).getProgress()).isEqualTo(90);
@@ -60,7 +60,7 @@ public void updateNotification_withProgress() {
6060
@Test
6161
public void updateNotification_withError() {
6262
firebaseAppDistributionNotificationsManager.updateNotification(
63-
1000, 1000, UpdateStatus.DOWNLOAD_FAILED);
63+
1000, 1000, R.string.download_failed);
6464
assertThat(shadowOf(notificationManager).size()).isEqualTo(1);
6565
Notification notification = shadowOf(notificationManager).getNotification(NOTIFICATION_TAG, 0);
6666
assertThat(shadowOf(notification).getProgress()).isEqualTo(100);
@@ -70,7 +70,7 @@ public void updateNotification_withError() {
7070
@Test
7171
public void updateNotification_withSuccess() {
7272
firebaseAppDistributionNotificationsManager.updateNotification(
73-
1000, 1000, UpdateStatus.DOWNLOADED);
73+
1000, 1000, R.string.download_completed);
7474
assertThat(shadowOf(notificationManager).size()).isEqualTo(1);
7575
Notification notification = shadowOf(notificationManager).getNotification(NOTIFICATION_TAG, 0);
7676
assertThat(shadowOf(notification).getProgress()).isEqualTo(100);
@@ -79,7 +79,8 @@ public void updateNotification_withSuccess() {
7979

8080
@Test
8181
public void updateNotification_withZeroTotalBytes_shows0Percent() {
82-
firebaseAppDistributionNotificationsManager.updateNotification(0, 0, UpdateStatus.DOWNLOADING);
82+
firebaseAppDistributionNotificationsManager.updateNotification(
83+
0, 0, R.string.downloading_app_update);
8384
assertThat(shadowOf(notificationManager).size()).isEqualTo(1);
8485
Notification notification = shadowOf(notificationManager).getNotification(NOTIFICATION_TAG, 0);
8586
assertThat(shadowOf(notification).getProgress()).isEqualTo(0);

0 commit comments

Comments
 (0)