Skip to content

Initial code structure for App Distribution Android SDK #2754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 30, 2021
Merged
45 changes: 45 additions & 0 deletions firebase-app-distribution/firebase-app-distribution.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

plugins {
id 'firebase-library'
}

android {
compileSdkVersion project.targetSdkVersion

defaultConfig {
minSdkVersion project.minSdkVersion
targetSdkVersion project.targetSdkVersion
multiDexEnabled true
versionName version
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
testOptions {
unitTests {
includeAndroidResources = true
}
}
}

dependencies {
implementation 'org.jetbrains:annotations:15.0'
implementation project(path: ':firebase-components')
implementation 'com.google.android.gms:play-services-tasks:17.0.0'
implementation project(path: ':firebase-common')
}
15 changes: 15 additions & 0 deletions firebase-app-distribution/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

version=0.0.1
28 changes: 28 additions & 0 deletions firebase-app-distribution/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2021 Google LLC -->
<!-- -->
<!-- Licensed under the Apache License, Version 2.0 (the "License"); -->
<!-- you may not use this file except in compliance with the License. -->
<!-- You may obtain a copy of the License at -->
<!-- -->
<!-- http://www.apache.org/licenses/LICENSE-2.0 -->
<!-- -->
<!-- Unless required by applicable law or agreed to in writing, software -->
<!-- distributed under the License is distributed on an "AS IS" BASIS, -->
<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -->
<!-- See the License for the specific language governing permissions and -->
<!-- limitations under the License. -->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.firebase.appdistribution">

<application>
<service
android:name="com.google.firebase.components.ComponentDiscoveryService"
android:exported="false">
<meta-data
android:name="com.google.firebase.components:com.google.firebase.appdistribution.FirebaseAppDistributionRegistrar"
android:value="com.google.firebase.components.ComponentRegistrar" />
</service>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.firebase.appdistribution;

import androidx.annotation.NonNull;

/**
* Data class for AppDistributionRelease object returned by checkForUpdate() and
* updateToLatestRelease()
*/
public final class AppDistributionRelease {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-blocking nit: you may want to add equals() and hashCode(), or use an @AutoValue altogether.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. We will add these in a follow-up PR

private final String displayVersion;
private final String buildVersion;
private final String releaseNotes;
private final BinaryType binaryType;

AppDistributionRelease(
String displayVersion, String buildVersion, String releaseNotes, BinaryType binaryType) {
this.displayVersion = displayVersion;
this.buildVersion = buildVersion;
this.releaseNotes = releaseNotes;
this.binaryType = binaryType;
}

/** The short bundle version of this build (example 1.0.0) */
@NonNull
public String getDisplayVersion() {
return displayVersion;
}

/** The bundle version of this build (example: 123) */
@NonNull
public String getBuildVersion() {
return buildVersion;
}

/** The release notes for this build */
@NonNull
public String getReleaseNotes() {
return releaseNotes;
}

/** The binary type for this build */
@NonNull
public BinaryType getBinaryType() {
return binaryType;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.firebase.appdistribution;

/** Enum of Android App Binary types, used in AppDistributionRelease */
public enum BinaryType {
AAB,
APK
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.firebase.appdistribution;

import androidx.annotation.NonNull;
import com.google.android.gms.tasks.Task;
import com.google.android.gms.tasks.Tasks;
import com.google.firebase.FirebaseApp;

public class FirebaseAppDistribution {

private final FirebaseApp firebaseApp;

/** Constructor for FirebaseAppDistribution */
FirebaseAppDistribution(@NonNull FirebaseApp firebaseApp) {
this.firebaseApp = firebaseApp;
}

/** @return a FirebaseInstallationsApi instance */
@NonNull
public static FirebaseAppDistribution getInstance() {
return new FirebaseAppDistribution(FirebaseApp.getInstance());
}

/**
* Updates the app to the latest release, if one is available. Returns the release information or
* null if no update is found. Performs the following actions: 1. If tester is not signed in,
* presents the tester with a Google sign in UI 2. Checks if a newer release is available. If so,
* presents the tester with a confirmation dialog to begin the download. 3. For APKs, downloads
* the binary and starts an installation intent. 4. For AABs, directs the tester to the Play app
* to complete the download and installation.
*/
@NonNull
public Task<AppDistributionRelease> updateToLatestRelease() {
return Tasks.forResult(null);
}

/**
* Returns an AppDistributionRelease if one is available for the current signed in tester. If no
* update is found, returns null. If tester is not signed in, presents the tester with a Google
* sign in UI
*/
@NonNull
public Task<AppDistributionRelease> checkForUpdate() {
return Tasks.forResult(null);
}

/**
* Updates app to the latest release. If the latest release is an APK, downloads the binary and
* starts an installation If the latest release is an AAB, directs the tester to the Play app to
* complete the download and installation.
*
* @throws an {@link Status.UPDATE_NOT_AVAILABLE_ERROR} exception if no new release is cached from
* checkForUpdate
*/
@NonNull
public UpdateTask updateApp() {
return (UpdateTask) Tasks.forResult(new UpdateState(0, 0, UpdateStatus.PENDING));
}

/** Signs in the App Distribution tester. Presents the tester with a Google sign in UI */
@NonNull
public Task<Void> signInTester() {
return Tasks.forResult(null);
}

/** Returns true if the App Distribution tester is signed in */
@NonNull
public boolean isTesterSignedIn() {
return false;
}

/** Signs out the App Distribution tester */
public void signOutTester() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.firebase.appdistribution;

import androidx.annotation.NonNull;
import com.google.firebase.FirebaseException;

/** Possible exceptions thrown in FirebaseAppDistribution */
public class FirebaseAppDistributionException extends FirebaseException {
public enum Status {
/** Unknown error. */
UNKNOWN,

/** Authentication failed */
AUTHENTICATION_FAILURE,

/** Authentication canceled */
AUTHENTICATION_CANCELED,

/** No Network available to make requests or the request timed out */
NETWORK_FAILURE,

/** Download failed */
DOWNLOAD_FAILURE,

/** Installation failed */
INSTALLATION_FAILURE,

/** Installation canceled */
INSTALLATION_CANCELED,

/** Update not available for the current tester and app */
UPDATE_NOT_AVAILABLE,

/** Installation failed due to signature mismatch */
INSTALLATION_FAILURE_SIGNATURE_MISMATCH,

/** App is in production */
APP_RUNNING_IN_PRODUCTION,

/** Download URL for release expired */
RELEASE_URL_EXPIRED,
}

@NonNull private final Status status;
@NonNull private final AppDistributionRelease release;

FirebaseAppDistributionException(
@NonNull Status status, @NonNull AppDistributionRelease release) {
this.status = status;
this.release = release;
}

/** Get cached release when error was thrown */
@NonNull
public AppDistributionRelease getRelease() {
return release;
}

@NonNull
public Status getErrorCode() {
return status;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.firebase.appdistribution;

import androidx.annotation.Keep;
import com.google.firebase.FirebaseApp;
import com.google.firebase.components.Component;
import com.google.firebase.components.ComponentRegistrar;
import com.google.firebase.components.Dependency;
import com.google.firebase.platforminfo.LibraryVersionComponent;
import java.util.Arrays;
import java.util.List;

/**
* Registers FirebaseAppDistribution
*
* @hide
*/
@Keep
public class FirebaseAppDistributionRegistrar implements ComponentRegistrar {
@Override
public List<Component<?>> getComponents() {
return Arrays.asList(
Component.builder(FirebaseAppDistribution.class)
.add(Dependency.required(FirebaseApp.class))
.factory(c -> new FirebaseAppDistribution(c.get(FirebaseApp.class)))
.build(),
LibraryVersionComponent.create("fire-app-distribution", BuildConfig.VERSION_NAME));
}
}
Loading