Skip to content

Commit 460fd3f

Browse files
andrewbibiloniRachel Prince
andauthored
Initial code structure for App Distribution Android SDK (#2754)
* Init commit * Fix formatting, add @nonnull in api, update SDK versions * Reformat code, add more @nonnull * Add new line at end of files * Remove optionals, address nits, remove Api from name * Change abstract to regular class * Implement registrar, add FirebaseApp as dependency * Create seperate classes for interfaces and enums * Add comments * Fix comments * Code clean up * Address API feedback Change data classes to public final classes Add UpdateTask class Update FirebaseAppDistributionException to use an enum instead of an IntDef Co-authored-by: Rachel Prince <[email protected]>
1 parent 7c1afeb commit 460fd3f

13 files changed

+516
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
plugins {
16+
id 'firebase-library'
17+
}
18+
19+
android {
20+
compileSdkVersion project.targetSdkVersion
21+
22+
defaultConfig {
23+
minSdkVersion project.minSdkVersion
24+
targetSdkVersion project.targetSdkVersion
25+
multiDexEnabled true
26+
versionName version
27+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
28+
}
29+
compileOptions {
30+
sourceCompatibility JavaVersion.VERSION_1_8
31+
targetCompatibility JavaVersion.VERSION_1_8
32+
}
33+
testOptions {
34+
unitTests {
35+
includeAndroidResources = true
36+
}
37+
}
38+
}
39+
40+
dependencies {
41+
implementation 'org.jetbrains:annotations:15.0'
42+
implementation project(path: ':firebase-components')
43+
implementation 'com.google.android.gms:play-services-tasks:17.0.0'
44+
implementation project(path: ':firebase-common')
45+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
version=0.0.1
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright 2021 Google LLC -->
3+
<!-- -->
4+
<!-- Licensed under the Apache License, Version 2.0 (the "License"); -->
5+
<!-- you may not use this file except in compliance with the License. -->
6+
<!-- You may obtain a copy of the License at -->
7+
<!-- -->
8+
<!-- http://www.apache.org/licenses/LICENSE-2.0 -->
9+
<!-- -->
10+
<!-- Unless required by applicable law or agreed to in writing, software -->
11+
<!-- distributed under the License is distributed on an "AS IS" BASIS, -->
12+
<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -->
13+
<!-- See the License for the specific language governing permissions and -->
14+
<!-- limitations under the License. -->
15+
16+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
17+
package="com.google.firebase.appdistribution">
18+
19+
<application>
20+
<service
21+
android:name="com.google.firebase.components.ComponentDiscoveryService"
22+
android:exported="false">
23+
<meta-data
24+
android:name="com.google.firebase.components:com.google.firebase.appdistribution.FirebaseAppDistributionRegistrar"
25+
android:value="com.google.firebase.components.ComponentRegistrar" />
26+
</service>
27+
</application>
28+
</manifest>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
/**
20+
* Data class for AppDistributionRelease object returned by checkForUpdate() and
21+
* updateToLatestRelease()
22+
*/
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+
37+
/** The short bundle version of this build (example 1.0.0) */
38+
@NonNull
39+
public String getDisplayVersion() {
40+
return displayVersion;
41+
}
42+
43+
/** The bundle version of this build (example: 123) */
44+
@NonNull
45+
public String getBuildVersion() {
46+
return buildVersion;
47+
}
48+
49+
/** The release notes for this build */
50+
@NonNull
51+
public String getReleaseNotes() {
52+
return releaseNotes;
53+
}
54+
55+
/** The binary type for this build */
56+
@NonNull
57+
public BinaryType getBinaryType() {
58+
return binaryType;
59+
}
60+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
/** Enum of Android App Binary types, used in AppDistributionRelease */
18+
public enum BinaryType {
19+
AAB,
20+
APK
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
import com.google.android.gms.tasks.Task;
19+
import com.google.android.gms.tasks.Tasks;
20+
import com.google.firebase.FirebaseApp;
21+
22+
public class FirebaseAppDistribution {
23+
24+
private final FirebaseApp firebaseApp;
25+
26+
/** Constructor for FirebaseAppDistribution */
27+
FirebaseAppDistribution(@NonNull FirebaseApp firebaseApp) {
28+
this.firebaseApp = firebaseApp;
29+
}
30+
31+
/** @return a FirebaseInstallationsApi instance */
32+
@NonNull
33+
public static FirebaseAppDistribution getInstance() {
34+
return new FirebaseAppDistribution(FirebaseApp.getInstance());
35+
}
36+
37+
/**
38+
* Updates the app to the latest release, if one is available. Returns the release information or
39+
* null if no update is found. Performs the following actions: 1. If tester is not signed in,
40+
* presents the tester with a Google sign in UI 2. Checks if a newer release is available. If so,
41+
* presents the tester with a confirmation dialog to begin the download. 3. For APKs, downloads
42+
* the binary and starts an installation intent. 4. For AABs, directs the tester to the Play app
43+
* to complete the download and installation.
44+
*/
45+
@NonNull
46+
public Task<AppDistributionRelease> updateToLatestRelease() {
47+
return Tasks.forResult(null);
48+
}
49+
50+
/**
51+
* Returns an AppDistributionRelease if one is available for the current signed in tester. If no
52+
* update is found, returns null. If tester is not signed in, presents the tester with a Google
53+
* sign in UI
54+
*/
55+
@NonNull
56+
public Task<AppDistributionRelease> checkForUpdate() {
57+
return Tasks.forResult(null);
58+
}
59+
60+
/**
61+
* Updates app to the latest release. If the latest release is an APK, downloads the binary and
62+
* starts an installation If the latest release is an AAB, directs the tester to the Play app to
63+
* complete the download and installation.
64+
*
65+
* @throws an {@link Status.UPDATE_NOT_AVAILABLE_ERROR} exception if no new release is cached from
66+
* checkForUpdate
67+
*/
68+
@NonNull
69+
public UpdateTask updateApp() {
70+
return (UpdateTask) Tasks.forResult(new UpdateState(0, 0, UpdateStatus.PENDING));
71+
}
72+
73+
/** Signs in the App Distribution tester. Presents the tester with a Google sign in UI */
74+
@NonNull
75+
public Task<Void> signInTester() {
76+
return Tasks.forResult(null);
77+
}
78+
79+
/** Returns true if the App Distribution tester is signed in */
80+
@NonNull
81+
public boolean isTesterSignedIn() {
82+
return false;
83+
}
84+
85+
/** Signs out the App Distribution tester */
86+
public void signOutTester() {}
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
import com.google.firebase.FirebaseException;
19+
20+
/** Possible exceptions thrown in FirebaseAppDistribution */
21+
public class FirebaseAppDistributionException extends FirebaseException {
22+
public enum Status {
23+
/** Unknown error. */
24+
UNKNOWN,
25+
26+
/** Authentication failed */
27+
AUTHENTICATION_FAILURE,
28+
29+
/** Authentication canceled */
30+
AUTHENTICATION_CANCELED,
31+
32+
/** No Network available to make requests or the request timed out */
33+
NETWORK_FAILURE,
34+
35+
/** Download failed */
36+
DOWNLOAD_FAILURE,
37+
38+
/** Installation failed */
39+
INSTALLATION_FAILURE,
40+
41+
/** Installation canceled */
42+
INSTALLATION_CANCELED,
43+
44+
/** Update not available for the current tester and app */
45+
UPDATE_NOT_AVAILABLE,
46+
47+
/** Installation failed due to signature mismatch */
48+
INSTALLATION_FAILURE_SIGNATURE_MISMATCH,
49+
50+
/** App is in production */
51+
APP_RUNNING_IN_PRODUCTION,
52+
53+
/** Download URL for release expired */
54+
RELEASE_URL_EXPIRED,
55+
}
56+
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+
}
65+
66+
/** Get cached release when error was thrown */
67+
@NonNull
68+
public AppDistributionRelease getRelease() {
69+
return release;
70+
}
71+
72+
@NonNull
73+
public Status getErrorCode() {
74+
return status;
75+
}
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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.Keep;
18+
import com.google.firebase.FirebaseApp;
19+
import com.google.firebase.components.Component;
20+
import com.google.firebase.components.ComponentRegistrar;
21+
import com.google.firebase.components.Dependency;
22+
import com.google.firebase.platforminfo.LibraryVersionComponent;
23+
import java.util.Arrays;
24+
import java.util.List;
25+
26+
/**
27+
* Registers FirebaseAppDistribution
28+
*
29+
* @hide
30+
*/
31+
@Keep
32+
public class FirebaseAppDistributionRegistrar implements ComponentRegistrar {
33+
@Override
34+
public List<Component<?>> getComponents() {
35+
return Arrays.asList(
36+
Component.builder(FirebaseAppDistribution.class)
37+
.add(Dependency.required(FirebaseApp.class))
38+
.factory(c -> new FirebaseAppDistribution(c.get(FirebaseApp.class)))
39+
.build(),
40+
LibraryVersionComponent.create("fire-app-distribution", BuildConfig.VERSION_NAME));
41+
}
42+
}

0 commit comments

Comments
 (0)