Skip to content

Commit 56d72ee

Browse files
fredquintanadiwu-arete
authored andcommitted
Fixes for multi-process access (#1042)
* Switch from using SharedPreferences to a flat file * Fixes for multi-process access - switch from shared prefs to a flat file - protect generate Fid for cross-process and cross-thread accesses - make doRegistration only read the prefs once at the beginning and clean up the flow - pass the forceRefresh flag into doRegistration rather than storing it in a global * revert the name of the FID prefs write call * fix formatting issues * Fix the cross process locking The check if a new FID was needed was not in the critical region. * some small changes from the review * fix the java format and update the api file
1 parent fdbc752 commit 56d72ee

17 files changed

+1119
-879
lines changed

firebase-installations/api.txt

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ package com.google.firebase.installations {
1717
}
1818

1919
public enum FirebaseInstallationsException.Status {
20-
enum_constant public static final com.google.firebase.installations.FirebaseInstallationsException.Status AUTHENTICATION_ERROR;
21-
enum_constant public static final com.google.firebase.installations.FirebaseInstallationsException.Status CLIENT_ERROR;
22-
enum_constant public static final com.google.firebase.installations.FirebaseInstallationsException.Status SDK_INTERNAL_ERROR;
20+
enum_constant public static final com.google.firebase.installations.FirebaseInstallationsException.Status BAD_CONFIG;
21+
}
22+
23+
public class RandomFidGenerator {
24+
ctor public RandomFidGenerator();
25+
method @NonNull public String createRandomFid();
2326
}
2427

2528
}
@@ -33,12 +36,13 @@ package com.google.firebase.installations.local {
3336

3437
public class PersistedInstallation {
3538
ctor public PersistedInstallation(@NonNull FirebaseApp);
36-
method @NonNull public boolean clear();
37-
method @NonNull public boolean insertOrUpdatePersistedInstallationEntry(@NonNull com.google.firebase.installations.local.PersistedInstallationEntry);
39+
method public void clearForTesting();
40+
method @NonNull public com.google.firebase.installations.local.PersistedInstallationEntry insertOrUpdatePersistedInstallationEntry(@NonNull com.google.firebase.installations.local.PersistedInstallationEntry);
3841
method @NonNull public com.google.firebase.installations.local.PersistedInstallationEntry readPersistedInstallationEntryValue();
3942
}
4043

4144
public enum PersistedInstallation.RegistrationStatus {
45+
enum_constant public static final com.google.firebase.installations.local.PersistedInstallation.RegistrationStatus ATTEMPT_MIGRATION;
4246
enum_constant public static final com.google.firebase.installations.local.PersistedInstallation.RegistrationStatus NOT_GENERATED;
4347
enum_constant public static final com.google.firebase.installations.local.PersistedInstallation.RegistrationStatus REGISTERED;
4448
enum_constant public static final com.google.firebase.installations.local.PersistedInstallation.RegistrationStatus REGISTER_ERROR;
@@ -59,7 +63,15 @@ package com.google.firebase.installations.local {
5963
method public boolean isNotGenerated();
6064
method public boolean isRegistered();
6165
method public boolean isUnregistered();
66+
method public boolean shouldAttemptMigration();
6267
method @NonNull public abstract com.google.firebase.installations.local.PersistedInstallationEntry.Builder toBuilder();
68+
method @NonNull public com.google.firebase.installations.local.PersistedInstallationEntry withAuthToken(@NonNull String, long, long);
69+
method @NonNull public com.google.firebase.installations.local.PersistedInstallationEntry withClearedAuthToken();
70+
method @NonNull public com.google.firebase.installations.local.PersistedInstallationEntry withFisError(@NonNull String);
71+
method @NonNull public com.google.firebase.installations.local.PersistedInstallationEntry withNoGeneratedFid();
72+
method @NonNull public com.google.firebase.installations.local.PersistedInstallationEntry withRegisteredFid(@NonNull String, @NonNull String, long, @Nullable String, long);
73+
method @NonNull public com.google.firebase.installations.local.PersistedInstallationEntry withUnregisteredFid(@NonNull String);
74+
field @NonNull public static com.google.firebase.installations.local.PersistedInstallationEntry INSTANCE;
6375
}
6476

6577
public abstract static class PersistedInstallationEntry.Builder {
@@ -107,8 +119,8 @@ package com.google.firebase.installations.remote {
107119
}
108120

109121
public enum InstallationResponse.ResponseCode {
122+
enum_constant public static final com.google.firebase.installations.remote.InstallationResponse.ResponseCode BAD_CONFIG;
110123
enum_constant public static final com.google.firebase.installations.remote.InstallationResponse.ResponseCode OK;
111-
enum_constant public static final com.google.firebase.installations.remote.InstallationResponse.ResponseCode SERVER_ERROR;
112124
}
113125

114126
public abstract class TokenResult {
@@ -117,7 +129,6 @@ package com.google.firebase.installations.remote {
117129
method @Nullable public abstract com.google.firebase.installations.remote.TokenResult.ResponseCode getResponseCode();
118130
method @Nullable public abstract String getToken();
119131
method @NonNull public abstract long getTokenExpirationTimestamp();
120-
method public boolean isSuccessful();
121132
method @NonNull public abstract com.google.firebase.installations.remote.TokenResult.Builder toBuilder();
122133
}
123134

@@ -130,9 +141,9 @@ package com.google.firebase.installations.remote {
130141
}
131142

132143
public enum TokenResult.ResponseCode {
133-
enum_constant public static final com.google.firebase.installations.remote.TokenResult.ResponseCode FID_ERROR;
144+
enum_constant public static final com.google.firebase.installations.remote.TokenResult.ResponseCode AUTH_ERROR;
145+
enum_constant public static final com.google.firebase.installations.remote.TokenResult.ResponseCode BAD_CONFIG;
134146
enum_constant public static final com.google.firebase.installations.remote.TokenResult.ResponseCode OK;
135-
enum_constant public static final com.google.firebase.installations.remote.TokenResult.ResponseCode REFRESH_TOKEN_ERROR;
136147
}
137148

138149
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
package com.google.firebase.installations;
16+
17+
import java.util.Calendar;
18+
19+
public class FakeCalendar extends Calendar {
20+
private long timeInMillis;
21+
22+
public FakeCalendar(long initialTimeInMillis) {
23+
timeInMillis = initialTimeInMillis;
24+
}
25+
26+
public long getTimeInMillis() {
27+
return timeInMillis;
28+
}
29+
30+
public void setTimeInMillis(long timeInMillis) {
31+
this.timeInMillis = timeInMillis;
32+
}
33+
34+
public void advanceTimeBySeconds(long deltaSeconds) {
35+
timeInMillis += (deltaSeconds * 1000L);
36+
}
37+
38+
@Override
39+
protected void computeTime() {}
40+
41+
@Override
42+
protected void computeFields() {}
43+
44+
@Override
45+
public void add(int i, int i1) {}
46+
47+
@Override
48+
public void roll(int i, boolean b) {}
49+
50+
@Override
51+
public int getMinimum(int i) {
52+
return 0;
53+
}
54+
55+
@Override
56+
public int getMaximum(int i) {
57+
return 0;
58+
}
59+
60+
@Override
61+
public int getGreatestMinimum(int i) {
62+
return 0;
63+
}
64+
65+
@Override
66+
public int getLeastMaximum(int i) {
67+
return 0;
68+
}
69+
}

0 commit comments

Comments
 (0)