Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/main/java/com/google/firebase/FirebaseApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ public String getName() {
return name;
}

/**
* Returns the specified {@link FirebaseOptions}.
/**
* Returns the specified {@link FirebaseOptions}.
*/
@NonNull
public FirebaseOptions getOptions() {
Expand Down Expand Up @@ -390,6 +390,10 @@ ThreadFactory getThreadFactory() {
return threadManager.getThreadFactory();
}

ScheduledExecutorService getScheduledExecutorService() {
return ensureScheduledExecutorService();
}

<T> ApiFuture<T> submit(Callable<T> command) {
checkNotNull(command);
return new ListenableFuture2ApiFuture<>(executors.getListeningExecutor().submit(command));
Expand All @@ -405,6 +409,17 @@ <T> ScheduledFuture<T> schedule(Callable<T> command, long delayMillis) {
}
}

ScheduledFuture<?> schedule(Runnable runnable, long delayMillis) {
checkNotNull(runnable);
try {
return ensureScheduledExecutorService()
.schedule(runnable, delayMillis, TimeUnit.MILLISECONDS);
} catch (Exception e) {
// This may fail if the underlying ThreadFactory does not support long-lived threads.
throw new UnsupportedOperationException("Scheduled tasks not supported", e);
}
}

void startTokenRefresher() {
synchronized (lock) {
checkNotDeleted();
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/google/firebase/ImplFirebaseTrampolines.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@

package com.google.firebase;

import com.google.api.core.ApiAsyncFunction;
import com.google.api.core.ApiFunction;
import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.firestore.FirestoreOptions;
import com.google.firebase.internal.FirebaseService;
import com.google.firebase.internal.NonNull;

import java.util.concurrent.Callable;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ThreadFactory;

/**
Expand Down Expand Up @@ -67,6 +72,23 @@ public static ThreadFactory getThreadFactory(@NonNull FirebaseApp app) {
return app.getThreadFactory();
}

public static <V, X> ApiFuture<X> transform(
ApiFuture<? extends V> input,
final ApiFunction<? super V, ? extends X> function,
@NonNull FirebaseApp app) {
return ApiFutures.transform(input, function, app.getScheduledExecutorService());
}

public static <V, X> ApiFuture<X> transformAsync(
ApiFuture<V> input, final ApiAsyncFunction<V, X> function, @NonNull FirebaseApp app) {
return ApiFutures.transformAsync(input, function, app.getScheduledExecutorService());
}

public static ScheduledFuture<?> schedule(
@NonNull FirebaseApp app, @NonNull Runnable runnable, long delayMillis) {
return app.schedule(runnable, delayMillis);
}

public static <T> ApiFuture<T> submitCallable(
@NonNull FirebaseApp app, @NonNull Callable<T> command) {
return app.submit(command);
Expand Down
166 changes: 166 additions & 0 deletions src/main/java/com/google/firebase/projectmanagement/AndroidApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/* Copyright 2018 Google Inc.
*
* 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.projectmanagement;

import com.google.api.core.ApiFuture;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import java.util.List;

/**
* An instance of this class is a reference to an Android App within a Firebase Project; it can be
* used to query detailed information about the App, modify the display name of the App, or download
* the configuration file for the App.
*
* <p>Note: the methods in this class make RPCs.
*/
public class AndroidApp {

private final AndroidAppService androidAppService;
private final String appId;

AndroidApp(String appId, AndroidAppService androidAppService) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(appId), "app ID cannot be null or empty");
this.appId = appId;
this.androidAppService = androidAppService;
}

String getAppId() {
return appId;
}

/**
* Retrieves detailed information about this Android App.
*
* @return an {@link AndroidAppMetadata} instance describing this App
* @throws FirebaseProjectManagementException if there was an error during the RPC
*/
public AndroidAppMetadata getMetadata() throws Exception {
return androidAppService.getAndroidApp(appId);
}

/**
* Asynchronously retrieves information about this Android App.
*
* @return an {@code ApiFuture} containing an {@link AndroidAppMetadata} instance describing this
* App
*/
public ApiFuture<AndroidAppMetadata> getMetadataAsync() {
return androidAppService.getAndroidAppAsync(appId);
}

/**
* Updates the Display Name attribute of this Android App to the one given.
*
* @throws FirebaseProjectManagementException if there was an error during the RPC
*/
public void setDisplayName(String newDisplayName) throws FirebaseProjectManagementException {
androidAppService.setAndroidDisplayName(appId, newDisplayName);
}

/**
* Asynchronously updates the Display Name attribute of this Android App to the one given.
*/
public ApiFuture<Void> setDisplayNameAsync(String newDisplayName) {
return androidAppService.setAndroidDisplayNameAsync(appId, newDisplayName);
}

/**
* Retrieves the configuration artifact associated with this Android App.
*
* @return a modified UTF-8 encoded {@code String} containing the contents of the artifact
* @throws FirebaseProjectManagementException if there was an error during the RPC
*/
public String getConfig() throws FirebaseProjectManagementException {
return androidAppService.getAndroidConfig(appId);
}

/**
* Asynchronously retrieves the configuration artifact associated with this Android App.
*
* @return an {@code ApiFuture} of a UTF-8 encoded {@code String} containing the contents of the
* artifact
*/
public ApiFuture<String> getConfigAsync() {
return androidAppService.getAndroidConfigAsync(appId);
}

/**
* Retrieves the entire list of SHA certificates associated with this Android app.
*
* @return a list of {@link ShaCertificate} containing resource name, SHA hash and certificate
* type
* @throws FirebaseProjectManagementException if there was an error during the RPC
*/
public List<ShaCertificate> getShaCertificates() throws FirebaseProjectManagementException {
return androidAppService.getShaCertificates(appId);
}

/**
* Asynchronously retrieves the entire list of SHA certificates associated with this Android app.
*
* @return an {@code ApiFuture} of a list of {@link ShaCertificate} containing resource name,
* SHA hash and certificate type
*/
public ApiFuture<List<ShaCertificate>> getShaCertificatesAsync() {
return androidAppService.getShaCertificatesAsync(appId);
}

/**
* Adds a SHA certificate to this Android app.
*
* @param certificateToAdd the SHA certificate to be added to this Android app
* @return a {@link ShaCertificate} that was created for this Android app, containing resource
* name, SHA hash, and certificate type
* @throws FirebaseProjectManagementException if there was an error during the RPC
*/
public ShaCertificate createShaCertificate(ShaCertificate certificateToAdd)
throws FirebaseProjectManagementException {
return androidAppService.createShaCertificate(appId, certificateToAdd);
}

/**
* Asynchronously adds a SHA certificate to this Android app.
*
* @param certificateToAdd the SHA certificate to be added to this Android app
* @return a {@code ApiFuture} of a {@link ShaCertificate} that was created for this Android app,
* containing resource name, SHA hash, and certificate type
*/
public ApiFuture<ShaCertificate> createShaCertificateAsync(ShaCertificate certificateToAdd) {
return androidAppService.createShaCertificateAsync(appId, certificateToAdd);
}

/**
* Removes a SHA certificate from this Android app.
*
* @param certificateToRemove the SHA certificate to be removed from this Android app
* @throws FirebaseProjectManagementException if there was an error during the RPC
*/
public void deleteShaCertificate(ShaCertificate certificateToRemove)
throws FirebaseProjectManagementException {
androidAppService.deleteShaCertificate(certificateToRemove.getName());
}

/**
* Asynchronously removes a SHA certificate from this Android app.
*
* @param certificateToRemove the SHA certificate to be removed from this Android app
*/
public ApiFuture<Void> deleteShaCertificateAsync(ShaCertificate certificateToRemove) {
return androidAppService.deleteShaCertificateAsync(certificateToRemove.getName());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/* Copyright 2018 Google Inc.
*
* 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.projectmanagement;

import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;

/**
* Contains detailed information about an Android App. Instances of this class are immutable.
*/
public class AndroidAppMetadata {

private final String name;
private final String appId;
private final String displayName;
private final String projectId;
private final String packageName;

AndroidAppMetadata(
String name, String appId, String displayName, String projectId, String packageName) {
this.name = Preconditions.checkNotNull(name, "Null name");
this.appId = Preconditions.checkNotNull(appId, "Null appId");
this.displayName = Preconditions.checkNotNull(displayName, "Null displayName");
this.projectId = Preconditions.checkNotNull(projectId, "Null projectId");
this.packageName = Preconditions.checkNotNull(packageName, "Null packageName");
}

/**
* Returns the fully qualified resource name of this Android App.
*/
public String getName() {
return name;
}

/**
* Returns the globally unique, Firebase-assigned identifier of this Android App. This ID is
* unique even across Apps of different platforms, such as iOS Apps.
*/
public String getAppId() {
return appId;
}

/**
* Returns the user-assigned display name of this Android App.
*/
public String getDisplayName() {
return displayName;
}

/**
* Returns the permanent, globally unique, user-assigned ID of the parent Project for this Android
* App.
*/
public String getProjectId() {
return projectId;
}

/**
* Returns the canonical package name of this Android app as it would appear in Play store.
*/
public String getPackageName() {
return packageName;
}

@Override
public String toString() {
return MoreObjects.toStringHelper("AndroidAppMetadata")
.add("name", name)
.add("appId", appId)
.add("displayName", displayName)
.add("projectId", projectId)
.add("packageName", packageName)
.toString();
}

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o instanceof AndroidAppMetadata) {
AndroidAppMetadata that = (AndroidAppMetadata) o;
return Objects.equal(this.name, that.name)
&& Objects.equal(this.appId, that.appId)
&& Objects.equal(this.displayName, that.displayName)
&& Objects.equal(this.projectId, that.projectId)
&& Objects.equal(this.packageName, that.packageName);
}
return false;
}

@Override
public int hashCode() {
return Objects.hashCode(name, appId, displayName, projectId, packageName);
}

}
Loading