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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,19 @@ The following libraries are available for the various Firebase products.
| [Cloud Functions](https://firebase.google.com/docs/functions) | `22.1.1` |
| [Remote Config](https://firebase.google.com/docs/remote-config) | `23.1.0`[^2] |
| [Installations](https://firebase.google.com/docs/projects/manage-installations) | `19.1.2` |
| [Google Analytics](https://firebase.google.com/docs/analytics) | N/A[^3] |
| [Cloud Messaging](https://firebase.google.com/docs/cloud-messaging) | N/A[^4] |
| [Performance Monitoring](https://firebase.google.com/docs/perf-mon) | N/A[^5] |

[^1]: Google has not open-sourced the Firebase Auth implementation for Android so a basic implementation using the Rest API is provided.
[^2]: Realtime updates (`addOnConfigUpdateListener`) and defaults from XML resources are not supported.
[^3]: Google Analytics has no client for the JVM, so the `com.google.firebase.analytics` API is a no-op: events, user
properties and consent are accepted and dropped, the instance and session IDs are null.
[^4]: Messages are received through a device registration the JVM does not have, so `FirebaseMessaging.getInstance()`
exists but its operations throw `UnsupportedOperationException`; `RemoteMessage` and its `Builder` are an in-memory
data holder.
[^5]: There is no Performance Monitoring client for the JVM, so traces and HTTP metrics are kept in memory: they record
their metrics and attributes, which can be read back, and report nothing.

Is the Firebase library or API you need missing? [Create an issue](https://github.com/GitLiveApp/firebase-java-sdk/issues/new?labels=API+coverage&template=increase-api-coverage.md&title=Add+%5Bclass+name%5D.%5Bfunction+name%5D+to+%5Blibrary+name) to request additional API coverage or be awesome and [submit a PR](https://github.com/GitLiveApp/firebase-java-sdk/fork).

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.8.2
version=0.8.3
7 changes: 7 additions & 0 deletions src/main/java/android/app/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package android.app

import android.content.ComponentCallbacks
import android.content.Context
import java.io.File

class Application : Context() {
var minSdkVersion: Int = 0
Expand All @@ -14,4 +15,10 @@ class Application : Context() {
}

interface ActivityLifecycleCallbacks

companion object {
/** The name of this process, which Firebase puts in the message of the error for a missing default app: the JVM's executable. */
@JvmStatic
fun getProcessName(): String = ProcessHandle.current().info().command().map { File(it).name }.orElse("java")
}
}
1 change: 1 addition & 0 deletions src/main/java/android/content/pm/PackageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public ServiceInfo getServiceInfo(ComponentName component, int flags) throws Nam
data.put("com.google.firebase.components:com.google.firebase.storage.StorageRegistrar", "com.google.firebase.components.ComponentRegistrar");
data.put("com.google.firebase.components:com.google.firebase.remoteconfig.RemoteConfigRegistrar", "com.google.firebase.components.ComponentRegistrar");
data.put("com.google.firebase.components:com.google.firebase.abt.component.AbtRegistrar", "com.google.firebase.components.ComponentRegistrar");
data.put("com.google.firebase.components:com.google.firebase.perf.FirebasePerfRegistrar", "com.google.firebase.components.ComponentRegistrar");
return new ServiceInfo(data);
}
throw new IllegalArgumentException(component.cls);
Expand Down
50 changes: 46 additions & 4 deletions src/main/java/android/os/Bundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,24 @@
import java.util.Set;

/**
* A mapping from String keys to values, with the Android class's semantics for the primitive, String and Bundle values
* the ported Firebase libraries use: a getter returns its default when the key is missing or the value has another
* type, {@link #containsKey} answers rather than throws, and keys may be null.
* A mapping from String keys to values, with the Android class's semantics for the primitive, String, Bundle and
* Parcelable values the ported Firebase libraries use: a getter returns its default when the key is missing or the
* value has another type, {@link #containsKey} answers rather than throws, and keys may be null. Like Android's it is
* itself a {@link Parcelable}, written as its entries.
*/
public class Bundle {
public class Bundle implements Parcelable {

public static final Parcelable.Creator<Bundle> CREATOR = new Parcelable.Creator<Bundle>() {
@Override
public Bundle createFromParcel(Parcel source) {
return source.readBundle();
}

@Override
public Bundle[] newArray(int size) {
return new Bundle[size];
}
};

private final Map<String, Object> data;

Expand Down Expand Up @@ -87,6 +100,15 @@ public void putBundle(String key, Bundle value) {
data.put(key, value);
}

public void putParcelable(String key, Parcelable value) {
data.put(key, value);
}

/** Stores an array of parcelables, such as the {@code items} of an Analytics e-commerce event. */
public void putParcelableArray(String key, Parcelable[] value) {
data.put(key, value);
}

public boolean getBoolean(String key) {
return getBoolean(key, false);
}
Expand Down Expand Up @@ -141,6 +163,26 @@ public Bundle getBundle(String key) {
return get(key, Bundle.class, null);
}

@SuppressWarnings("unchecked")
public <T extends Parcelable> T getParcelable(String key) {
return (T) get(key, Parcelable.class, null);
}

public Parcelable[] getParcelableArray(String key) {
return get(key, Parcelable[].class, null);
}

@Override
public int describeContents() {
return 0;
}

/** Writes the entries with {@link Parcel#writeBundle}; {@link #CREATOR} reads them back with {@link Parcel#readBundle()}. */
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeBundle(this);
}

private <T> T get(String key, Class<T> type, T defaultValue) {
Object value = data.get(key);
return type.isInstance(value) ? type.cast(value) : defaultValue;
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/android/os/Parcel.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public final class Parcel {
private static final int VAL_LIST = 11;
private static final int VAL_BYTEARRAY = 13;
private static final int VAL_STRINGARRAY = 14;
private static final int VAL_PARCELABLEARRAY = 16;
private static final int VAL_BYTE = 20;
private static final int VAL_SERIALIZABLE = 21;

Expand Down Expand Up @@ -350,6 +351,18 @@ public void writeParcelable(@Nullable Parcelable p, int parcelableFlags) {
p.writeToParcel(this, parcelableFlags);
}

/** Writes the length of the array, or -1 for a null array, followed by each element with {@link #writeParcelable}. */
public <T extends Parcelable> void writeParcelableArray(@Nullable T[] value, int parcelableFlags) {
if (value == null) {
writeInt(-1);
return;
}
writeInt(value.length);
for (T element : value) {
writeParcelable(element, parcelableFlags);
}
}

/**
* Writes a serialized snapshot of the object, so that changing it afterwards does not change the parcel and each
* {@link #readSerializable()} returns a fresh copy.
Expand Down Expand Up @@ -405,6 +418,9 @@ public void writeValue(@Nullable Object v) {
} else if (v instanceof String[]) {
writeInt(VAL_STRINGARRAY);
writeStringList(Arrays.asList((String[]) v));
} else if (v instanceof Parcelable[]) {
writeInt(VAL_PARCELABLEARRAY);
writeParcelableArray((Parcelable[]) v, 0);
} else if (v instanceof Byte) {
writeInt(VAL_BYTE);
writeByte((Byte) v);
Expand Down Expand Up @@ -628,6 +644,20 @@ public <T extends Parcelable> T readParcelable(@Nullable ClassLoader loader) {
return (T) creator.createFromParcel(this);
}

/** Reads the array {@link #writeParcelableArray} wrote, each element through its class's {@code CREATOR}. */
@Nullable
public Parcelable[] readParcelableArray(@Nullable ClassLoader loader) {
int n = readInt();
if (n < 0) {
return null;
}
Parcelable[] result = new Parcelable[n];
for (int i = 0; i < n; i++) {
result[i] = readParcelable(loader);
}
return result;
}

/**
* Deserializes a fresh copy of the object {@link #writeSerializable} wrote. This is the only place the parcel
* deserializes anything: {@link #unmarshall} keeps serialized objects as bytes until a caller asks for them here.
Expand Down Expand Up @@ -672,6 +702,8 @@ public Object readValue(@Nullable ClassLoader loader) {
case VAL_STRINGARRAY:
ArrayList<String> strings = createStringArrayList();
return strings == null ? null : strings.toArray(new String[0]);
case VAL_PARCELABLEARRAY:
return readParcelableArray(loader);
case VAL_BYTE:
return readByte();
case VAL_SERIALIZABLE:
Expand Down
66 changes: 66 additions & 0 deletions src/main/java/com/google/firebase/analytics/Analytics.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* The Kotlin extensions the Android SDK's firebase-analytics ships as com.google.firebase.analytics.AnalyticsKt, with
* their ParametersBuilder and ConsentBuilder, so that code written against them compiles against this SDK like it does
* against the other ported libraries' facades.
*/
package com.google.firebase.analytics

import android.os.Bundle
import com.google.firebase.Firebase

/** Returns the [FirebaseAnalytics] instance of the default app. */
val Firebase.analytics: FirebaseAnalytics
get() = FirebaseAnalytics.getInstance(com.google.firebase.FirebaseApp.getInstance().applicationContext)

/** Logs an event with the parameters set by [block], e.g. `logEvent(FirebaseAnalytics.Event.LOGIN) { param(FirebaseAnalytics.Param.METHOD, "email") }`. */
inline fun FirebaseAnalytics.logEvent(name: String, block: ParametersBuilder.() -> Unit) {
logEvent(name, ParametersBuilder().apply(block).bundle)
}

/** Sets the consent settings assigned by [block], e.g. `setConsent { adStorage = FirebaseAnalytics.ConsentStatus.GRANTED }`. */
inline fun FirebaseAnalytics.setConsent(block: ConsentBuilder.() -> Unit) {
setConsent(ConsentBuilder().apply(block).asMap())
}

/** The parameters of an event logged with [logEvent]. */
class ParametersBuilder {
/** The parameters set so far, as a [Bundle] the block may also edit directly. */
val bundle: Bundle = Bundle()

fun param(key: String, value: Double) {
bundle.putDouble(key, value)
}

fun param(key: String, value: Long) {
bundle.putLong(key, value)
}

fun param(key: String, value: String) {
bundle.putString(key, value)
}

fun param(key: String, value: Bundle) {
bundle.putBundle(key, value)
}

/** An array of bundles, such as the [FirebaseAnalytics.Param.ITEMS] of an e-commerce event. */
fun param(key: String, value: Array<Bundle>) {
bundle.putParcelableArray(key, value)
}
}

/** The consent settings set with [setConsent]; a setting left null is not changed. */
class ConsentBuilder {
var adStorage: FirebaseAnalytics.ConsentStatus? = null
var analyticsStorage: FirebaseAnalytics.ConsentStatus? = null
var adUserData: FirebaseAnalytics.ConsentStatus? = null
var adPersonalization: FirebaseAnalytics.ConsentStatus? = null

/** The settings that were assigned. */
fun asMap(): Map<FirebaseAnalytics.ConsentType, FirebaseAnalytics.ConsentStatus> = buildMap {
adStorage?.let { put(FirebaseAnalytics.ConsentType.AD_STORAGE, it) }
analyticsStorage?.let { put(FirebaseAnalytics.ConsentType.ANALYTICS_STORAGE, it) }
adUserData?.let { put(FirebaseAnalytics.ConsentType.AD_USER_DATA, it) }
adPersonalization?.let { put(FirebaseAnalytics.ConsentType.AD_PERSONALIZATION, it) }
}
}
Loading
Loading