Skip to content

Commit 013e422

Browse files
author
Rachel Prince
committed
Address API feedback
Change data classes to public final classes Add UpdateTask class Update FirebaseAppDistributionException to use an enum instead of an IntDef
1 parent b304d11 commit 013e422

File tree

6 files changed

+131
-77
lines changed

6 files changed

+131
-77
lines changed

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,44 @@
1717
import androidx.annotation.NonNull;
1818

1919
/**
20-
* Interface for AppDistributonRelease object returned by checkForUpdate() and
20+
* Data class for AppDistributionRelease object returned by checkForUpdate() and
2121
* updateToLatestRelease()
2222
*/
23-
public interface AppDistributionRelease {
23+
public final class AppDistributionRelease {
24+
private final String displayVersion;
25+
private final String buildVersion;
26+
private final String releaseNotes;
27+
private final BinaryType binaryType;
28+
29+
AppDistributionRelease(
30+
String displayVersion, String buildVersion, String releaseNotes, BinaryType binaryType) {
31+
this.displayVersion = displayVersion;
32+
this.buildVersion = buildVersion;
33+
this.releaseNotes = releaseNotes;
34+
this.binaryType = binaryType;
35+
}
36+
2437
/** The short bundle version of this build (example 1.0.0) */
2538
@NonNull
26-
public String getDisplayVersion();
39+
public String getDisplayVersion() {
40+
return displayVersion;
41+
}
2742

2843
/** The bundle version of this build (example: 123) */
2944
@NonNull
30-
public String getBuildVersion();
45+
public String getBuildVersion() {
46+
return buildVersion;
47+
}
3148

3249
/** The release notes for this build */
3350
@NonNull
34-
public String getReleaseNotes();
51+
public String getReleaseNotes() {
52+
return releaseNotes;
53+
}
3554

3655
/** The binary type for this build */
3756
@NonNull
38-
public BinaryType getBinaryType();
57+
public BinaryType getBinaryType() {
58+
return binaryType;
59+
}
3960
}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@
1818
import com.google.android.gms.tasks.Task;
1919
import com.google.android.gms.tasks.Tasks;
2020
import com.google.firebase.FirebaseApp;
21-
import org.jetbrains.annotations.Nullable;
2221

2322
public class FirebaseAppDistribution {
2423

2524
private final FirebaseApp firebaseApp;
2625

2726
/** Constructor for FirebaseAppDistribution */
28-
public FirebaseAppDistribution(@NonNull FirebaseApp firebaseApp) {
27+
FirebaseAppDistribution(@NonNull FirebaseApp firebaseApp) {
2928
this.firebaseApp = firebaseApp;
3029
}
3130

@@ -63,12 +62,12 @@ public Task<AppDistributionRelease> checkForUpdate() {
6362
* starts an installation If the latest release is an AAB, directs the tester to the Play app to
6463
* complete the download and installation.
6564
*
66-
* @throws an UPDATE_NOT_AVAIALBLE exception if no new release is cached from checkForUpdate
67-
* @param updateProgressListener a callback function invoked as the update progresses
65+
* @throws an {@link Status.UPDATE_NOT_AVAILABLE_ERROR} exception if no new release is cached from
66+
* checkForUpdate
6867
*/
6968
@NonNull
70-
public Task<Void> updateApp(@Nullable UpdateProgressListener updateProgressListener) {
71-
return Tasks.forResult(null);
69+
public UpdateTask updateApp() {
70+
return (UpdateTask) Tasks.forResult(new UpdateState(0, 0, UpdateStatus.PENDING));
7271
}
7372

7473
/** Signs in the App Distribution tester. Presents the tester with a Google sign in UI */

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

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -14,69 +14,63 @@
1414

1515
package com.google.firebase.appdistribution;
1616

17-
import androidx.annotation.IntDef;
1817
import androidx.annotation.NonNull;
1918
import com.google.firebase.FirebaseException;
20-
import java.lang.annotation.Retention;
21-
import java.lang.annotation.RetentionPolicy;
2219

2320
/** Possible exceptions thrown in FirebaseAppDistribution */
24-
public abstract class FirebaseAppDistributionException extends FirebaseException {
25-
/** Unknown error. */
26-
public static final int UNKNOWN_ERROR = 1;
21+
public class FirebaseAppDistributionException extends FirebaseException {
22+
public enum Status {
23+
/** Unknown error. */
24+
UNKNOWN,
2725

28-
/** Authentication failed */
29-
public static final int AUTHENTICATION_FAILURE_ERROR = 2;
26+
/** Authentication failed */
27+
AUTHENTICATION_FAILURE,
3028

31-
/** Authentication canceled */
32-
public static final int AUTHENTICATION_CANCELED_ERROR = 3;
29+
/** Authentication canceled */
30+
AUTHENTICATION_CANCELED,
3331

34-
/** No Network available to make requests or the request timed out */
35-
public static final int NETWORK_FAILURE_ERROR = 4;
32+
/** No Network available to make requests or the request timed out */
33+
NETWORK_FAILURE,
3634

37-
/** Download failed */
38-
public static final int DOWNLOAD_FAILURE_ERROR = 5;
35+
/** Download failed */
36+
DOWNLOAD_FAILURE,
3937

40-
/** Installation failed */
41-
public static final int INSTALLATION_FAILURE_ERROR = 6;
38+
/** Installation failed */
39+
INSTALLATION_FAILURE,
4240

43-
/** Installation canceled */
44-
public static final int INSTALLATION_CANCELED_ERROR = 7;
41+
/** Installation canceled */
42+
INSTALLATION_CANCELED,
4543

46-
/** Update not available for the current tester and app */
47-
public static final int UPDATE_NOT_AVAILABLE_ERROR = 8;
44+
/** Update not available for the current tester and app */
45+
UPDATE_NOT_AVAILABLE,
4846

49-
/** Installation failed due to signature mismatch */
50-
public static final int INSTALLATION_FAILURE_SIGNATURE_MISMATCH_ERROR = 9;
47+
/** Installation failed due to signature mismatch */
48+
INSTALLATION_FAILURE_SIGNATURE_MISMATCH,
5149

52-
/** App is in production */
53-
public static final int APP_RUNNING_IN_PRODUCTION_ERROR = 10;
50+
/** App is in production */
51+
APP_RUNNING_IN_PRODUCTION,
5452

55-
/** Download URL for release expired */
56-
public static final int RELEASE_URL_EXPIRED_ERROR = 11;
53+
/** Download URL for release expired */
54+
RELEASE_URL_EXPIRED,
55+
}
5756

58-
/** Get error code */
59-
public abstract int getCode();
57+
@NonNull private final Status status;
58+
@NonNull private final AppDistributionRelease release;
59+
60+
FirebaseAppDistributionException(
61+
@NonNull Status status, @NonNull AppDistributionRelease release) {
62+
this.status = status;
63+
this.release = release;
64+
}
6065

6166
/** Get cached release when error was thrown */
6267
@NonNull
63-
public abstract AppDistributionRelease getRelease();
64-
65-
/** The set of FirebaseAppDistribution status codes. */
66-
@IntDef({
67-
FirebaseAppDistributionException.UNKNOWN_ERROR,
68-
FirebaseAppDistributionException.AUTHENTICATION_FAILURE_ERROR,
69-
FirebaseAppDistributionException.AUTHENTICATION_CANCELED_ERROR,
70-
FirebaseAppDistributionException.NETWORK_FAILURE_ERROR,
71-
FirebaseAppDistributionException.DOWNLOAD_FAILURE_ERROR,
72-
FirebaseAppDistributionException.INSTALLATION_FAILURE_ERROR,
73-
FirebaseAppDistributionException.INSTALLATION_CANCELED_ERROR,
74-
FirebaseAppDistributionException.UPDATE_NOT_AVAILABLE_ERROR,
75-
FirebaseAppDistributionException.INSTALLATION_FAILURE_SIGNATURE_MISMATCH_ERROR,
76-
FirebaseAppDistributionException.APP_RUNNING_IN_PRODUCTION_ERROR,
77-
FirebaseAppDistributionException.RELEASE_URL_EXPIRED_ERROR,
78-
})
79-
@Retention(RetentionPolicy.CLASS)
80-
/** Interface for converting int to error code */
81-
public @interface Code {}
68+
public AppDistributionRelease getRelease() {
69+
return release;
70+
}
71+
72+
@NonNull
73+
public Status getErrorCode() {
74+
return status;
75+
}
8276
}

firebase-app-distribution/src/main/java/com/google/firebase/appdistribution/UpdateProgress.java renamed to firebase-app-distribution/src/main/java/com/google/firebase/appdistribution/OnProgressListener.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,7 @@
1616

1717
import androidx.annotation.NonNull;
1818

19-
/** Interface to get download progress for APKs and the status of the update. Used in updateApp. */
20-
public interface UpdateProgress {
21-
/** The number of bytes downloaded so far for the APK. Returns -1 if called on an AAB. */
22-
@NonNull
23-
public long getApkBytesDownloaded();
24-
25-
/** The total number of bytes to download for the APK. Returns -1 if called on an AAB. */
26-
@NonNull
27-
public long getApkTotalBytesToDownload();
28-
29-
@NonNull
30-
/** returns the current state of the update */
31-
public UpdateStatus getUpdateStatus();
19+
/** A listener that is called periodically during execution of the {@link UpdateTask}. */
20+
public interface OnProgressListener {
21+
void onProgressUpdate(@NonNull UpdateState updateState);
3222
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2021 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.appdistribution;
16+
17+
import androidx.annotation.NonNull;
18+
19+
/** Data class to get download progress for APKs and the status of the update. Used in updateApp. */
20+
public final class UpdateState {
21+
private final long apkBytesDownloaded;
22+
private final long apkTotalBytesToDownload;
23+
private final UpdateStatus updateStatus;
24+
25+
UpdateState(long apkBytesDownloaded, long apkTotalBytesToDownload, UpdateStatus updateStatus) {
26+
this.apkBytesDownloaded = apkBytesDownloaded;
27+
this.apkTotalBytesToDownload = apkTotalBytesToDownload;
28+
this.updateStatus = updateStatus;
29+
}
30+
31+
/** The number of bytes downloaded so far for the APK. Returns -1 if called on an AAB. */
32+
@NonNull
33+
public long getApkBytesDownloaded() {
34+
return apkBytesDownloaded;
35+
}
36+
37+
/** The total number of bytes to download for the APK. Returns -1 if called on an AAB. */
38+
@NonNull
39+
public long getApkTotalBytesToDownload() {
40+
return apkTotalBytesToDownload;
41+
}
42+
43+
@NonNull
44+
/** returns the current state of the update */
45+
public UpdateStatus getUpdateStatus() {
46+
return updateStatus;
47+
}
48+
}
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
package com.google.firebase.appdistribution;
1616

1717
import androidx.annotation.NonNull;
18+
import com.google.android.gms.tasks.Task;
19+
20+
public abstract class UpdateTask extends Task<UpdateState> {
1821

19-
/** Interface to subscribe to status updates on the release update process. Called by updateApp. */
20-
public interface UpdateProgressListener {
2122
/**
22-
* Method invoked during updating to track progress by modifying UpdateProgress object
23+
* Adds a listener that is called periodically while the UpdateTask executes.
2324
*
24-
* @param UpdateProgress object to be modified
25+
* @return this Task
2526
*/
26-
public void onProgressUpdate(@NonNull UpdateProgress updateProgress);
27+
@NonNull
28+
public abstract UpdateTask addOnProgressListener(@NonNull OnProgressListener listener);
2729
}

0 commit comments

Comments
 (0)