Skip to content

Commit b401d31

Browse files
committed
Merge branch 'master' of github.com:firebase/firebase-android-sdk into arete-floc
2 parents dc1a63c + 8d104e5 commit b401d31

File tree

84 files changed

+3155
-840
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+3155
-840
lines changed

.idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/measurement/apksize/ApkSizeTableBuilder.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ class ApkSizeTableBuilder {
2929
throw new IllegalStateException("No sizes added")
3030
}
3131

32-
def table = "|------------------ APK Sizes ------------------|\n"
33-
table += "|-- project --|-- build type --|-- size in bytes --|\n"
32+
def table = "|-------------------- APK Sizes ------------------|\n"
33+
table += "|--- project ---|-- build type --|-- size in bytes --|\n"
3434

3535
table += sdkSizes.collect {
36-
sprintf("|%-19s|%-19s|%-21s|", it.get(0), it.get(1), it.get(2))
36+
sprintf("|%-21s|%-19s|%-21s|", it.get(0), it.get(1), it.get(2))
3737
}.join("\n")
3838

3939
return table

buildSrc/src/test/groovy/com/google/firebase/gradle/plugins/measurement/apksize/ApkSizeTableBuilderTest.groovy

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import org.junit.runners.JUnit4
2525
public class ApkSizeTableBuilderTest {
2626

2727
private static final String HEADER =
28-
"|------------------ APK Sizes ------------------|\n" +
29-
"|-- project --|-- build type --|-- size in bytes --|\n"
28+
"|-------------------- APK Sizes ------------------|\n" +
29+
"|--- project ---|-- build type --|-- size in bytes --|\n"
3030

3131
@Test(expected = IllegalStateException.class)
3232
public void toTableString_throwsWhenZeroAdded() {
@@ -37,7 +37,7 @@ public class ApkSizeTableBuilderTest {
3737
@Test
3838
public void toTableString_withOneMeasurement() {
3939
def expected = HEADER +
40-
"|firebase foo |debug |255000 |"
40+
"|firebase foo |debug |255000 |"
4141

4242
def builder = new ApkSizeTableBuilder()
4343
builder.addApkSize("firebase foo", "debug", 255000)
@@ -48,9 +48,9 @@ public class ApkSizeTableBuilderTest {
4848
@Test
4949
public void toTableString_withThreeMeasurements() {
5050
def expected = HEADER +
51-
"|firebase foo |debug |255000 |\n" +
52-
"|google loo |release |4000 |\n" +
53-
"|Appy Snap App |Snappy |781000 |"
51+
"|firebase foo |debug |255000 |\n" +
52+
"|google loo |release |4000 |\n" +
53+
"|Appy Snap App |Snappy |781000 |"
5454

5555
def builder = new ApkSizeTableBuilder()
5656
builder.addApkSize("firebase foo", "debug", 255000)

firebase-abt/firebase-abt.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ android {
8282

8383
dependencies {
8484
implementation project(':firebase-common')
85-
implementation project(':protolite-well-known-types')
8685
implementation ('com.google.firebase:firebase-measurement-connector:18.0.0') {
8786
exclude group: "com.google.firebase", module: "firebase-common"
8887
}
88+
implementation 'com.google.android.gms:play-services-basement:17.0.0'
8989
implementation 'com.google.protobuf:protobuf-lite:3.0.1'
9090
testImplementation 'org.mockito:mockito-core:2.25.0'
9191
testImplementation 'com.google.truth:truth:0.44'

firebase-abt/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
version=18.0.1
1+
version=18.1.0
22
latestReleasedVersion=18.0.0
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2019 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+
/** @hide */
16+
package com.google.firebase.abt.component;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2019 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+
/** @hide */
16+
package com.google.firebase.abt;

firebase-config/src/main/java/com/google/firebase/remoteconfig/internal/ConfigStorageClient.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ private ConfigStorageClient(Context context, String fileName) {
7676
*/
7777
public synchronized Void write(ConfigContainer container) throws IOException {
7878
// TODO(issues/262): Consider using the AtomicFile class instead.
79-
try (FileOutputStream outputStream = context.openFileOutput(fileName, Context.MODE_PRIVATE)) {
79+
FileOutputStream outputStream = context.openFileOutput(fileName, Context.MODE_PRIVATE);
80+
try {
8081
outputStream.write(container.toString().getBytes(JSON_STRING_ENCODING));
82+
} finally {
83+
outputStream.close();
8184
}
8285
return null;
8386
}
@@ -90,7 +93,10 @@ public synchronized Void write(ConfigContainer container) throws IOException {
9093
*/
9194
@Nullable
9295
public synchronized ConfigContainer read() throws IOException {
93-
try (FileInputStream fileInputStream = context.openFileInput(fileName)) {
96+
97+
FileInputStream fileInputStream = null;
98+
try {
99+
fileInputStream = context.openFileInput(fileName);
94100
byte[] bytes = new byte[fileInputStream.available()];
95101
fileInputStream.read(bytes, 0, bytes.length);
96102
String containerJsonString = new String(bytes, JSON_STRING_ENCODING);
@@ -100,6 +106,8 @@ public synchronized ConfigContainer read() throws IOException {
100106
} catch (JSONException | FileNotFoundException e) {
101107
// File might not have been written to yet, so this not an irrecoverable error.
102108
return null;
109+
} finally {
110+
if (fileInputStream != null) fileInputStream.close();
103111
}
104112
}
105113

firebase-database/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# Unreleased
1+
# 18.0.1
2+
- [changed] The SDK now reports the correct version number (via
3+
`FirebaseDatabase.getSdkVersion()`).
4+
5+
# 17.0.0
26
- [changed] Added `@RestrictTo` annotations to discourage the use of APIs that
37
are not public. This affects internal APIs that were previously obfuscated
48
and are not mentioned in our documentation.

firebase-database/src/main/java/com/google/firebase/database/FirebaseDatabase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
@PublicApi
3939
public class FirebaseDatabase {
4040

41-
private static final String SDK_VERSION = "3.0.0";
41+
private static final String SDK_VERSION = BuildConfig.VERSION_NAME;
4242

4343
private final FirebaseApp app;
4444
private final RepoInfo repoInfo;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
version=17.0.1
2-
latestReleasedVersion=17.0.0
1+
version=17.0.2
2+
latestReleasedVersion=17.0.1
33
android.enableUnitTestBinaryResources=true

firebase-firestore/CHANGELOG.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
# Unreleased
2+
- [changed] Transactions are now more flexible. Some sequences of operations
3+
that were previously incorrectly disallowed are now allowed. For example,
4+
after reading a document that doesn't exist, you can now set it multiple
5+
times successfully in a transaction.
6+
- [fixed] Fixed an issue where query results were temporarily missing documents
7+
that previously had not matched but had been updated to now match the
8+
query (#155).
9+
10+
# 20.2.0
11+
- [feature] Added a `@DocumentId` annotation which can be used on a
12+
`DocumentReference` or `String` property in a POJO to indicate that the SDK
13+
should automatically populate it with the document's ID.
214
- [fixed] Fixed an internal assertion that was triggered when an update
315
with a `FieldValue.serverTimestamp()` and an update with a
416
`FieldValue.increment()` were pending for the same document (#491).
@@ -7,11 +19,11 @@
719
small subset of the documents in a collection.
820
- [changed] Instead of failing silently, Firestore now crashes the client app
921
if it fails to load SSL Ciphers. To avoid these crashes, you must bundle
10-
Conscrypt to support non-GMSCore devices on Android KitKat or JellyBean (see
22+
Conscrypt to support non-GMSCore devices on Android API level 19 (KitKat) or
23+
earlier (for more information, refer to
1124
https://github.com/grpc/grpc-java/blob/master/SECURITY.md#tls-on-android).
12-
- [feature] Added a `@DocumentId` annotation which can be used on a
13-
`DocumentReference` or `String` property in a POJO to indicate that the SDK
14-
should automatically populate it with the document's ID.
25+
- [changed] Failed transactions now fail with the exception from the last
26+
attempt instead of always failing with an exception with code `ABORTED`.
1527

1628
# 20.1.0
1729
- [changed] SSL and gRPC initialization now happens on a separate thread, which

firebase-firestore/ktx/src/test/java/com/google/firebase/firestore/TestUtil.java

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,17 @@
1919
import static com.google.firebase.firestore.testutil.TestUtil.key;
2020
import static org.mockito.Mockito.mock;
2121

22-
import androidx.annotation.Nullable;
2322
import com.google.android.gms.tasks.Task;
2423
import com.google.firebase.database.collection.ImmutableSortedSet;
2524
import com.google.firebase.firestore.core.DocumentViewChange;
2625
import com.google.firebase.firestore.core.DocumentViewChange.Type;
2726
import com.google.firebase.firestore.core.ViewSnapshot;
28-
import com.google.firebase.firestore.local.QueryData;
2927
import com.google.firebase.firestore.model.Document;
3028
import com.google.firebase.firestore.model.DocumentKey;
3129
import com.google.firebase.firestore.model.DocumentSet;
3230
import com.google.firebase.firestore.model.ResourcePath;
3331
import com.google.firebase.firestore.model.value.ObjectValue;
34-
import com.google.firebase.firestore.remote.WatchChangeAggregator;
3532
import java.util.ArrayList;
36-
import java.util.HashMap;
3733
import java.util.List;
3834
import java.util.Map;
3935
import org.junit.Assert;
@@ -138,36 +134,6 @@ public static QuerySnapshot querySnapshot(
138134
return new QuerySnapshot(query(path), viewSnapshot, FIRESTORE);
139135
}
140136

141-
/**
142-
* An implementation of TargetMetadataProvider that provides controlled access to the
143-
* `TargetMetadataProvider` callbacks. Any target accessed via these callbacks must be registered
144-
* beforehand via `setSyncedKeys()`.
145-
*/
146-
public static class TestTargetMetadataProvider
147-
implements WatchChangeAggregator.TargetMetadataProvider {
148-
final Map<Integer, ImmutableSortedSet<DocumentKey>> syncedKeys = new HashMap<>();
149-
final Map<Integer, QueryData> queryData = new HashMap<>();
150-
151-
@Override
152-
public ImmutableSortedSet<DocumentKey> getRemoteKeysForTarget(int targetId) {
153-
return syncedKeys.get(targetId) != null
154-
? syncedKeys.get(targetId)
155-
: DocumentKey.emptyKeySet();
156-
}
157-
158-
@Nullable
159-
@Override
160-
public QueryData getQueryDataForTarget(int targetId) {
161-
return queryData.get(targetId);
162-
}
163-
164-
/** Sets or replaces the local state for the provided query data. */
165-
public void setSyncedKeys(QueryData queryData, ImmutableSortedSet<DocumentKey> keys) {
166-
this.queryData.put(queryData.getTargetId(), queryData);
167-
this.syncedKeys.put(queryData.getTargetId(), keys);
168-
}
169-
}
170-
171137
public static <T> T waitFor(Task<T> task) {
172138
if (!task.isComplete()) {
173139
Robolectric.flushBackgroundThreadScheduler();

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/AccessHelper.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,16 @@ public static FirebaseFirestore newFirebaseFirestore(
3131
String persistenceKey,
3232
CredentialsProvider credentialsProvider,
3333
AsyncQueue asyncQueue,
34-
FirebaseApp firebaseApp) {
34+
FirebaseApp firebaseApp,
35+
FirebaseFirestore.InstanceRegistry instanceRegistry) {
3536
return new FirebaseFirestore(
36-
context, databaseId, persistenceKey, credentialsProvider, asyncQueue, firebaseApp);
37+
context,
38+
databaseId,
39+
persistenceKey,
40+
credentialsProvider,
41+
asyncQueue,
42+
firebaseApp,
43+
instanceRegistry);
3744
}
3845

3946
/** Makes the shutdown method accessible. */

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/FirestoreTest.java

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testCollection;
2121
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testCollectionWithDocs;
2222
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testDocument;
23+
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testFirebaseApp;
2324
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testFirestore;
2425
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.waitFor;
2526
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.waitForException;
@@ -30,6 +31,7 @@
3031
import static org.junit.Assert.assertFalse;
3132
import static org.junit.Assert.assertNotEquals;
3233
import static org.junit.Assert.assertNotNull;
34+
import static org.junit.Assert.assertNotSame;
3335
import static org.junit.Assert.assertNull;
3436
import static org.junit.Assert.assertSame;
3537
import static org.junit.Assert.assertTrue;
@@ -38,6 +40,7 @@
3840
import androidx.test.ext.junit.runners.AndroidJUnit4;
3941
import com.google.android.gms.tasks.Task;
4042
import com.google.android.gms.tasks.TaskCompletionSource;
43+
import com.google.firebase.FirebaseApp;
4144
import com.google.firebase.Timestamp;
4245
import com.google.firebase.firestore.FirebaseFirestoreException.Code;
4346
import com.google.firebase.firestore.Query.Direction;
@@ -1023,4 +1026,74 @@ public void testClearPersistenceWhileRunningFails() {
10231026
FirebaseFirestoreException firestoreException = (FirebaseFirestoreException) e;
10241027
assertEquals(Code.FAILED_PRECONDITION, firestoreException.getCode());
10251028
}
1029+
1030+
@Test
1031+
public void testRestartFirestoreLeadsToNewInstance() {
1032+
FirebaseApp app = testFirebaseApp();
1033+
FirebaseFirestore instance = FirebaseFirestore.getInstance(app);
1034+
FirebaseFirestore sameInstance = FirebaseFirestore.getInstance(app);
1035+
1036+
assertSame(instance, sameInstance);
1037+
waitFor(instance.document("abc/123").set(Collections.singletonMap("field", 100L)));
1038+
1039+
instance.shutdown();
1040+
FirebaseFirestore newInstance = FirebaseFirestore.getInstance(app);
1041+
1042+
// Verify new instance works.
1043+
DocumentSnapshot doc = waitFor(newInstance.document("abc/123").get());
1044+
assertEquals(doc.get("field"), 100L);
1045+
waitFor(newInstance.document("abc/123").delete());
1046+
1047+
// Verify it is different instance.
1048+
assertNotSame(instance, newInstance);
1049+
}
1050+
1051+
@Test
1052+
public void testAppDeleteLeadsToFirestoreShutdown() {
1053+
FirebaseApp app = testFirebaseApp();
1054+
FirebaseFirestore instance = FirebaseFirestore.getInstance(app);
1055+
waitFor(instance.document("abc/123").set(Collections.singletonMap("Field", 100)));
1056+
1057+
app.delete();
1058+
1059+
assertTrue(instance.getClient().isShutdown());
1060+
}
1061+
1062+
@Test
1063+
public void testNewOperationThrowsAfterFirestoreShutdown() {
1064+
FirebaseFirestore instance = testFirestore();
1065+
DocumentReference reference = instance.document("abc/123");
1066+
waitFor(reference.set(Collections.singletonMap("Field", 100)));
1067+
1068+
instance.shutdown();
1069+
1070+
final String expectedMessage = "The client has already been shutdown";
1071+
expectError(() -> waitFor(reference.get()), expectedMessage);
1072+
expectError(() -> waitFor(reference.update("Field", 1)), expectedMessage);
1073+
expectError(
1074+
() -> waitFor(reference.set(Collections.singletonMap("Field", 1))), expectedMessage);
1075+
expectError(
1076+
() -> waitFor(instance.runBatch((batch) -> batch.update(reference, "Field", 1))),
1077+
expectedMessage);
1078+
expectError(
1079+
() -> waitFor(instance.runTransaction(transaction -> transaction.get(reference))),
1080+
expectedMessage);
1081+
}
1082+
1083+
@Test
1084+
public void testShutdownCalledMultipleTimes() {
1085+
FirebaseFirestore instance = testFirestore();
1086+
DocumentReference reference = instance.document("abc/123");
1087+
waitFor(reference.set(Collections.singletonMap("Field", 100)));
1088+
1089+
instance.shutdown();
1090+
1091+
final String expectedMessage = "The client has already been shutdown";
1092+
expectError(() -> waitFor(reference.get()), expectedMessage);
1093+
1094+
// Calling a second time should go through and change nothing.
1095+
instance.shutdown();
1096+
1097+
expectError(() -> waitFor(reference.get()), expectedMessage);
1098+
}
10261099
}

0 commit comments

Comments
 (0)