diff --git a/firebase-installations/api.txt b/firebase-installations/api.txt index 2686a066ace..b99b2cacaa9 100644 --- a/firebase-installations/api.txt +++ b/firebase-installations/api.txt @@ -25,45 +25,45 @@ package com.google.firebase.installations { package com.google.firebase.installations.local { - public class PersistedFid { - ctor public PersistedFid(@NonNull FirebaseApp); + public class PersistedInstallation { + ctor public PersistedInstallation(@NonNull FirebaseApp); method @NonNull public boolean clear(); - method @NonNull public boolean insertOrUpdatePersistedFidEntry(@NonNull com.google.firebase.installations.local.PersistedFidEntry); - method @NonNull public com.google.firebase.installations.local.PersistedFidEntry readPersistedFidEntryValue(); + method @NonNull public boolean insertOrUpdatePersistedInstallationEntry(@NonNull com.google.firebase.installations.local.PersistedInstallationEntry); + method @NonNull public com.google.firebase.installations.local.PersistedInstallationEntry readPersistedInstallationEntryValue(); } - public enum PersistedFid.RegistrationStatus { - enum_constant public static final com.google.firebase.installations.local.PersistedFid.RegistrationStatus NOT_GENERATED; - enum_constant public static final com.google.firebase.installations.local.PersistedFid.RegistrationStatus REGISTERED; - enum_constant public static final com.google.firebase.installations.local.PersistedFid.RegistrationStatus REGISTER_ERROR; - enum_constant public static final com.google.firebase.installations.local.PersistedFid.RegistrationStatus UNREGISTERED; + public enum PersistedInstallation.RegistrationStatus { + enum_constant public static final com.google.firebase.installations.local.PersistedInstallation.RegistrationStatus NOT_GENERATED; + enum_constant public static final com.google.firebase.installations.local.PersistedInstallation.RegistrationStatus REGISTERED; + enum_constant public static final com.google.firebase.installations.local.PersistedInstallation.RegistrationStatus REGISTER_ERROR; + enum_constant public static final com.google.firebase.installations.local.PersistedInstallation.RegistrationStatus UNREGISTERED; } - public abstract class PersistedFidEntry { - ctor public PersistedFidEntry(); - method @NonNull public static com.google.firebase.installations.local.PersistedFidEntry.Builder builder(); + public abstract class PersistedInstallationEntry { + ctor public PersistedInstallationEntry(); + method @NonNull public static com.google.firebase.installations.local.PersistedInstallationEntry.Builder builder(); method @Nullable public abstract String getAuthToken(); method public abstract long getExpiresInSecs(); method @Nullable public abstract String getFirebaseInstallationId(); method @Nullable public abstract String getRefreshToken(); - method @NonNull public abstract com.google.firebase.installations.local.PersistedFid.RegistrationStatus getRegistrationStatus(); + method @NonNull public abstract com.google.firebase.installations.local.PersistedInstallation.RegistrationStatus getRegistrationStatus(); method public abstract long getTokenCreationEpochInSecs(); method public boolean isErrored(); method public boolean isNotGenerated(); method public boolean isRegistered(); method public boolean isUnregistered(); - method @NonNull public abstract com.google.firebase.installations.local.PersistedFidEntry.Builder toBuilder(); + method @NonNull public abstract com.google.firebase.installations.local.PersistedInstallationEntry.Builder toBuilder(); } - public abstract static class PersistedFidEntry.Builder { - ctor public PersistedFidEntry.Builder(); - method @NonNull public abstract com.google.firebase.installations.local.PersistedFidEntry build(); - method @NonNull public abstract com.google.firebase.installations.local.PersistedFidEntry.Builder setAuthToken(@Nullable String); - method @NonNull public abstract com.google.firebase.installations.local.PersistedFidEntry.Builder setExpiresInSecs(long); - method @NonNull public abstract com.google.firebase.installations.local.PersistedFidEntry.Builder setFirebaseInstallationId(@NonNull String); - method @NonNull public abstract com.google.firebase.installations.local.PersistedFidEntry.Builder setRefreshToken(@Nullable String); - method @NonNull public abstract com.google.firebase.installations.local.PersistedFidEntry.Builder setRegistrationStatus(@NonNull com.google.firebase.installations.local.PersistedFid.RegistrationStatus); - method @NonNull public abstract com.google.firebase.installations.local.PersistedFidEntry.Builder setTokenCreationEpochInSecs(long); + public abstract static class PersistedInstallationEntry.Builder { + ctor public PersistedInstallationEntry.Builder(); + method @NonNull public abstract com.google.firebase.installations.local.PersistedInstallationEntry build(); + method @NonNull public abstract com.google.firebase.installations.local.PersistedInstallationEntry.Builder setAuthToken(@Nullable String); + method @NonNull public abstract com.google.firebase.installations.local.PersistedInstallationEntry.Builder setExpiresInSecs(long); + method @NonNull public abstract com.google.firebase.installations.local.PersistedInstallationEntry.Builder setFirebaseInstallationId(@NonNull String); + method @NonNull public abstract com.google.firebase.installations.local.PersistedInstallationEntry.Builder setRefreshToken(@Nullable String); + method @NonNull public abstract com.google.firebase.installations.local.PersistedInstallationEntry.Builder setRegistrationStatus(@NonNull com.google.firebase.installations.local.PersistedInstallation.RegistrationStatus); + method @NonNull public abstract com.google.firebase.installations.local.PersistedInstallationEntry.Builder setTokenCreationEpochInSecs(long); } } diff --git a/firebase-installations/src/androidTest/java/com/google/firebase/installations/FirebaseInstallationsInstrumentedTest.java b/firebase-installations/src/androidTest/java/com/google/firebase/installations/FirebaseInstallationsInstrumentedTest.java index d216bd66cbb..594d301fac0 100644 --- a/firebase-installations/src/androidTest/java/com/google/firebase/installations/FirebaseInstallationsInstrumentedTest.java +++ b/firebase-installations/src/androidTest/java/com/google/firebase/installations/FirebaseInstallationsInstrumentedTest.java @@ -15,7 +15,7 @@ package com.google.firebase.installations; import static com.google.common.truth.Truth.assertWithMessage; -import static com.google.firebase.installations.FisAndroidTestConstants.DEFAULT_PERSISTED_FID_ENTRY; +import static com.google.firebase.installations.FisAndroidTestConstants.DEFAULT_PERSISTED_INSTALLATION_ENTRY; import static com.google.firebase.installations.FisAndroidTestConstants.INVALID_TEST_FID; import static com.google.firebase.installations.FisAndroidTestConstants.TEST_API_KEY; import static com.google.firebase.installations.FisAndroidTestConstants.TEST_APP_ID_1; @@ -32,7 +32,7 @@ import static com.google.firebase.installations.FisAndroidTestConstants.TEST_REFRESH_TOKEN; import static com.google.firebase.installations.FisAndroidTestConstants.TEST_TOKEN_EXPIRATION_TIMESTAMP; import static com.google.firebase.installations.FisAndroidTestConstants.TEST_TOKEN_EXPIRATION_TIMESTAMP_2; -import static com.google.firebase.installations.local.PersistedFidEntrySubject.assertThat; +import static com.google.firebase.installations.local.PersistedInstallationEntrySubject.assertThat; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; @@ -50,9 +50,9 @@ import com.google.android.gms.tasks.Tasks; import com.google.firebase.FirebaseApp; import com.google.firebase.FirebaseOptions; -import com.google.firebase.installations.local.PersistedFid; -import com.google.firebase.installations.local.PersistedFid.RegistrationStatus; -import com.google.firebase.installations.local.PersistedFidEntry; +import com.google.firebase.installations.local.PersistedInstallation; +import com.google.firebase.installations.local.PersistedInstallation.RegistrationStatus; +import com.google.firebase.installations.local.PersistedInstallationEntry; import com.google.firebase.installations.remote.FirebaseInstallationServiceClient; import com.google.firebase.installations.remote.FirebaseInstallationServiceException; import java.util.concurrent.ExecutionException; @@ -80,62 +80,62 @@ public class FirebaseInstallationsInstrumentedTest { private FirebaseApp firebaseApp; private ExecutorService executor; - private PersistedFid persistedFid; + private PersistedInstallation persistedInstallation; @Mock private FirebaseInstallationServiceClient backendClientReturnsOk; @Mock private FirebaseInstallationServiceClient backendClientReturnsError; - @Mock private PersistedFid persistedFidReturnsError; + @Mock private PersistedInstallation persistedInstallationReturnsError; @Mock private Utils mockUtils; - @Mock private PersistedFid mockPersistedFid; + @Mock private PersistedInstallation mockPersistedInstallation; @Mock private FirebaseInstallationServiceClient mockClient; - private static final PersistedFidEntry REGISTERED_FID_ENTRY = - PersistedFidEntry.builder() + private static final PersistedInstallationEntry REGISTERED_INSTALLATION_ENTRY = + PersistedInstallationEntry.builder() .setFirebaseInstallationId(TEST_FID_1) .setAuthToken(TEST_AUTH_TOKEN) .setRefreshToken(TEST_REFRESH_TOKEN) .setTokenCreationEpochInSecs(TEST_CREATION_TIMESTAMP_2) .setExpiresInSecs(TEST_TOKEN_EXPIRATION_TIMESTAMP) - .setRegistrationStatus(PersistedFid.RegistrationStatus.REGISTERED) + .setRegistrationStatus(PersistedInstallation.RegistrationStatus.REGISTERED) .build(); - private static final PersistedFidEntry EXPIRED_AUTH_TOKEN_ENTRY = - PersistedFidEntry.builder() + private static final PersistedInstallationEntry EXPIRED_AUTH_TOKEN_ENTRY = + PersistedInstallationEntry.builder() .setFirebaseInstallationId(TEST_FID_1) .setAuthToken(TEST_AUTH_TOKEN) .setRefreshToken(TEST_REFRESH_TOKEN) .setTokenCreationEpochInSecs(TEST_CREATION_TIMESTAMP_1) .setExpiresInSecs(TEST_TOKEN_EXPIRATION_TIMESTAMP_2) - .setRegistrationStatus(PersistedFid.RegistrationStatus.REGISTERED) + .setRegistrationStatus(PersistedInstallation.RegistrationStatus.REGISTERED) .build(); - private static final PersistedFidEntry UNREGISTERED_FID_ENTRY = - PersistedFidEntry.builder() + private static final PersistedInstallationEntry UNREGISTERED_INSTALLATION_ENTRY = + PersistedInstallationEntry.builder() .setFirebaseInstallationId(TEST_FID_1) .setAuthToken("") .setRefreshToken("") .setTokenCreationEpochInSecs(TEST_CREATION_TIMESTAMP_1) .setExpiresInSecs(0) - .setRegistrationStatus(PersistedFid.RegistrationStatus.UNREGISTERED) + .setRegistrationStatus(PersistedInstallation.RegistrationStatus.UNREGISTERED) .build(); - private static final PersistedFidEntry INVALID_FID_ENTRY = - PersistedFidEntry.builder() + private static final PersistedInstallationEntry INVALID_INSTALLATION_ENTRY = + PersistedInstallationEntry.builder() .setFirebaseInstallationId(INVALID_TEST_FID) .setAuthToken("") .setRefreshToken("") .setTokenCreationEpochInSecs(TEST_CREATION_TIMESTAMP_1) .setExpiresInSecs(0) - .setRegistrationStatus(PersistedFid.RegistrationStatus.UNREGISTERED) + .setRegistrationStatus(PersistedInstallation.RegistrationStatus.UNREGISTERED) .build(); - private static final PersistedFidEntry UPDATED_AUTH_TOKEN_ENTRY = - PersistedFidEntry.builder() + private static final PersistedInstallationEntry UPDATED_AUTH_TOKEN_ENTRY = + PersistedInstallationEntry.builder() .setFirebaseInstallationId(TEST_FID_1) .setAuthToken(TEST_AUTH_TOKEN_2) .setRefreshToken(TEST_REFRESH_TOKEN) .setTokenCreationEpochInSecs(TEST_CREATION_TIMESTAMP_2) .setExpiresInSecs(TEST_TOKEN_EXPIRATION_TIMESTAMP) - .setRegistrationStatus(PersistedFid.RegistrationStatus.REGISTERED) + .setRegistrationStatus(PersistedInstallation.RegistrationStatus.REGISTERED) .build(); @Before @@ -151,7 +151,7 @@ public void setUp() throws FirebaseInstallationServiceException { .setProjectId(TEST_PROJECT_ID) .setApiKey(TEST_API_KEY) .build()); - persistedFid = new PersistedFid(firebaseApp); + persistedInstallation = new PersistedInstallation(firebaseApp); when(backendClientReturnsOk.createFirebaseInstallation( anyString(), anyString(), anyString(), anyString())) @@ -161,9 +161,10 @@ public void setUp() throws FirebaseInstallationServiceException { anyString(), anyString(), anyString(), anyString())) .thenReturn(TEST_INSTALLATION_TOKEN_RESULT); - when(persistedFidReturnsError.insertOrUpdatePersistedFidEntry(any())).thenReturn(false); - when(persistedFidReturnsError.readPersistedFidEntryValue()) - .thenReturn(DEFAULT_PERSISTED_FID_ENTRY); + when(persistedInstallationReturnsError.insertOrUpdatePersistedInstallationEntry(any())) + .thenReturn(false); + when(persistedInstallationReturnsError.readPersistedInstallationEntryValue()) + .thenReturn(DEFAULT_PERSISTED_INSTALLATION_ENTRY); when(backendClientReturnsError.createFirebaseInstallation( anyString(), anyString(), anyString(), anyString())) @@ -188,40 +189,42 @@ public void setUp() throws FirebaseInstallationServiceException { @After public void cleanUp() throws Exception { - persistedFid.clear(); + persistedInstallation.clear(); } @Test - public void testGetId_PersistedFidOk_BackendOk() throws Exception { - when(mockUtils.isAuthTokenExpired(REGISTERED_FID_ENTRY)).thenReturn(false); + public void testGetId_PersistedInstallationOk_BackendOk() throws Exception { + when(mockUtils.isAuthTokenExpired(REGISTERED_INSTALLATION_ENTRY)).thenReturn(false); FirebaseInstallations firebaseInstallations = new FirebaseInstallations( - executor, firebaseApp, backendClientReturnsOk, persistedFid, mockUtils); + executor, firebaseApp, backendClientReturnsOk, persistedInstallation, mockUtils); // No exception, means success. assertWithMessage("getId Task failed.") .that(Tasks.await(firebaseInstallations.getId())) .isNotEmpty(); - PersistedFidEntry entryValue = persistedFid.readPersistedFidEntryValue(); + PersistedInstallationEntry entryValue = + persistedInstallation.readPersistedInstallationEntryValue(); assertThat(entryValue).hasFid(TEST_FID_1); // Waiting for Task that registers FID on the FIS Servers executor.awaitTermination(500, TimeUnit.MILLISECONDS); - PersistedFidEntry updatedFidEntry = persistedFid.readPersistedFidEntryValue(); - assertThat(updatedFidEntry).hasFid(TEST_FID_1); - assertThat(updatedFidEntry).hasRegistrationStatus(RegistrationStatus.REGISTERED); + PersistedInstallationEntry updatedInstallationEntry = + persistedInstallation.readPersistedInstallationEntryValue(); + assertThat(updatedInstallationEntry).hasFid(TEST_FID_1); + assertThat(updatedInstallationEntry).hasRegistrationStatus(RegistrationStatus.REGISTERED); } @Test public void testGetId_multipleCalls_sameFIDReturned() throws Exception { - when(mockUtils.isAuthTokenExpired(REGISTERED_FID_ENTRY)).thenReturn(false); + when(mockUtils.isAuthTokenExpired(REGISTERED_INSTALLATION_ENTRY)).thenReturn(false); when(backendClientReturnsOk.createFirebaseInstallation( anyString(), anyString(), anyString(), anyString())) .thenReturn(TEST_INSTALLATION_RESPONSE); FirebaseInstallations firebaseInstallations = new FirebaseInstallations( - executor, firebaseApp, backendClientReturnsOk, persistedFid, mockUtils); + executor, firebaseApp, backendClientReturnsOk, persistedInstallation, mockUtils); // Call getId multiple times Task task1 = firebaseInstallations.getId(); @@ -238,60 +241,69 @@ public void testGetId_multipleCalls_sameFIDReturned() throws Exception { .isEqualTo(TEST_FID_1); verify(backendClientReturnsOk, times(1)) .createFirebaseInstallation(TEST_API_KEY, TEST_FID_1, TEST_PROJECT_ID, TEST_APP_ID_1); - PersistedFidEntry updatedFidEntry = persistedFid.readPersistedFidEntryValue(); - assertThat(updatedFidEntry).hasFid(TEST_FID_1); - assertThat(updatedFidEntry).hasRegistrationStatus(RegistrationStatus.REGISTERED); + PersistedInstallationEntry updatedInstallationEntry = + persistedInstallation.readPersistedInstallationEntryValue(); + assertThat(updatedInstallationEntry).hasFid(TEST_FID_1); + assertThat(updatedInstallationEntry).hasRegistrationStatus(RegistrationStatus.REGISTERED); } @Test public void testGetId_invalidFid_storesValidFidFromResponse() throws Exception { - // Update local storage with fid entry that has invalid fid. - persistedFid.insertOrUpdatePersistedFidEntry(INVALID_FID_ENTRY); - when(mockUtils.isAuthTokenExpired(REGISTERED_FID_ENTRY)).thenReturn(false); + // Update local storage with installation entry that has invalid fid. + persistedInstallation.insertOrUpdatePersistedInstallationEntry(INVALID_INSTALLATION_ENTRY); + when(mockUtils.isAuthTokenExpired(REGISTERED_INSTALLATION_ENTRY)).thenReturn(false); FirebaseInstallations firebaseInstallations = new FirebaseInstallations( - executor, firebaseApp, backendClientReturnsOk, persistedFid, mockUtils); + executor, firebaseApp, backendClientReturnsOk, persistedInstallation, mockUtils); // No exception, means success. assertWithMessage("getId Task failed.") .that(Tasks.await(firebaseInstallations.getId())) .isNotEmpty(); - PersistedFidEntry entryValue = persistedFid.readPersistedFidEntryValue(); + PersistedInstallationEntry entryValue = + persistedInstallation.readPersistedInstallationEntryValue(); assertThat(entryValue).hasFid(INVALID_TEST_FID); // Waiting for Task that registers FID on the FIS Servers executor.awaitTermination(500, TimeUnit.MILLISECONDS); - PersistedFidEntry updatedFidEntry = persistedFid.readPersistedFidEntryValue(); - // After FID registration is complete, fid entry is updated with valid fid. - assertThat(updatedFidEntry).hasFid(TEST_FID_1); - assertThat(updatedFidEntry).hasRegistrationStatus(RegistrationStatus.REGISTERED); + PersistedInstallationEntry updatedInstallationEntry = + persistedInstallation.readPersistedInstallationEntryValue(); + // After FID registration is complete, installation entry is updated with valid fid. + assertThat(updatedInstallationEntry).hasFid(TEST_FID_1); + assertThat(updatedInstallationEntry).hasRegistrationStatus(RegistrationStatus.REGISTERED); } @Test - public void testGetId_PersistedFidOk_BackendError() throws Exception { + public void testGetId_PersistedInstallationOk_BackendError() throws Exception { FirebaseInstallations firebaseInstallations = new FirebaseInstallations( - executor, firebaseApp, backendClientReturnsError, persistedFid, mockUtils); + executor, firebaseApp, backendClientReturnsError, persistedInstallation, mockUtils); Tasks.await(firebaseInstallations.getId()); - PersistedFidEntry entryValue = persistedFid.readPersistedFidEntryValue(); + PersistedInstallationEntry entryValue = + persistedInstallation.readPersistedInstallationEntryValue(); assertThat(entryValue).hasFid(TEST_FID_1); // Waiting for Task that registers FID on the FIS Servers executor.awaitTermination(500, TimeUnit.MILLISECONDS); - PersistedFidEntry updatedFidEntry = persistedFid.readPersistedFidEntryValue(); - assertThat(updatedFidEntry).hasFid(TEST_FID_1); - assertThat(updatedFidEntry).hasRegistrationStatus(RegistrationStatus.REGISTER_ERROR); + PersistedInstallationEntry updatedInstallationEntry = + persistedInstallation.readPersistedInstallationEntryValue(); + assertThat(updatedInstallationEntry).hasFid(TEST_FID_1); + assertThat(updatedInstallationEntry).hasRegistrationStatus(RegistrationStatus.REGISTER_ERROR); } @Test - public void testGetId_PersistedFidError_BackendOk() throws InterruptedException { + public void testGetId_PersistedInstallationError_BackendOk() throws InterruptedException { FirebaseInstallations firebaseInstallations = new FirebaseInstallations( - executor, firebaseApp, backendClientReturnsOk, persistedFidReturnsError, mockUtils); + executor, + firebaseApp, + backendClientReturnsOk, + persistedInstallationReturnsError, + mockUtils); // Expect exception try { @@ -316,29 +328,32 @@ public void testGetId_fidRegistrationUncheckedException_statusUpdated() throws E invocation -> { throw new InterruptedException(); }); - when(mockUtils.isAuthTokenExpired(REGISTERED_FID_ENTRY)).thenReturn(false); + when(mockUtils.isAuthTokenExpired(REGISTERED_INSTALLATION_ENTRY)).thenReturn(false); FirebaseInstallations firebaseInstallations = - new FirebaseInstallations(executor, firebaseApp, mockClient, persistedFid, mockUtils); + new FirebaseInstallations( + executor, firebaseApp, mockClient, persistedInstallation, mockUtils); Tasks.await(firebaseInstallations.getId()); - PersistedFidEntry entryValue = persistedFid.readPersistedFidEntryValue(); + PersistedInstallationEntry entryValue = + persistedInstallation.readPersistedInstallationEntryValue(); assertThat(entryValue).hasFid(TEST_FID_1); // Waiting for Task that registers FID on the FIS Servers executor.awaitTermination(500, TimeUnit.MILLISECONDS); // Validate that registration status is REGISTER_ERROR - PersistedFidEntry updatedFidEntry = persistedFid.readPersistedFidEntryValue(); - assertThat(updatedFidEntry).hasFid(TEST_FID_1); - assertThat(updatedFidEntry).hasRegistrationStatus(RegistrationStatus.REGISTER_ERROR); + PersistedInstallationEntry updatedInstallationEntry = + persistedInstallation.readPersistedInstallationEntryValue(); + assertThat(updatedInstallationEntry).hasFid(TEST_FID_1); + assertThat(updatedInstallationEntry).hasRegistrationStatus(RegistrationStatus.REGISTER_ERROR); } @Test public void testGetId_expiredAuthTokenUncheckedException_statusUpdated() throws Exception { - // Update local storage with fid entry that has auth token expired. - persistedFid.insertOrUpdatePersistedFidEntry(EXPIRED_AUTH_TOKEN_ENTRY); + // Update local storage with installation entry that has auth token expired. + persistedInstallation.insertOrUpdatePersistedInstallationEntry(EXPIRED_AUTH_TOKEN_ENTRY); // Mocking unchecked exception on FIS generateAuthToken when(mockClient.generateAuthToken(anyString(), anyString(), anyString(), anyString())) .thenAnswer( @@ -348,45 +363,50 @@ public void testGetId_expiredAuthTokenUncheckedException_statusUpdated() throws when(mockUtils.isAuthTokenExpired(EXPIRED_AUTH_TOKEN_ENTRY)).thenReturn(true); FirebaseInstallations firebaseInstallations = - new FirebaseInstallations(executor, firebaseApp, mockClient, persistedFid, mockUtils); + new FirebaseInstallations( + executor, firebaseApp, mockClient, persistedInstallation, mockUtils); assertWithMessage("getId Task failed") .that(Tasks.await(firebaseInstallations.getId())) .isNotEmpty(); - PersistedFidEntry entryValue = persistedFid.readPersistedFidEntryValue(); + PersistedInstallationEntry entryValue = + persistedInstallation.readPersistedInstallationEntryValue(); assertThat(entryValue).hasFid(TEST_FID_1); // Waiting for Task that generates auth token with the FIS Servers executor.awaitTermination(500, TimeUnit.MILLISECONDS); // Validate that registration status is REGISTER_ERROR - PersistedFidEntry updatedFidEntry = persistedFid.readPersistedFidEntryValue(); - assertThat(updatedFidEntry).hasFid(TEST_FID_1); - assertThat(updatedFidEntry).hasRegistrationStatus(RegistrationStatus.REGISTER_ERROR); + PersistedInstallationEntry updatedInstallationEntry = + persistedInstallation.readPersistedInstallationEntryValue(); + assertThat(updatedInstallationEntry).hasFid(TEST_FID_1); + assertThat(updatedInstallationEntry).hasRegistrationStatus(RegistrationStatus.REGISTER_ERROR); } @Test public void testGetId_expiredAuthToken_refreshesAuthToken() throws Exception { - // Update local storage with fid entry that has auth token expired. - persistedFid.insertOrUpdatePersistedFidEntry(EXPIRED_AUTH_TOKEN_ENTRY); + // Update local storage with installation entry that has auth token expired. + persistedInstallation.insertOrUpdatePersistedInstallationEntry(EXPIRED_AUTH_TOKEN_ENTRY); when(mockUtils.isAuthTokenExpired(EXPIRED_AUTH_TOKEN_ENTRY)).thenReturn(true); FirebaseInstallations firebaseInstallations = new FirebaseInstallations( - executor, firebaseApp, backendClientReturnsOk, persistedFid, mockUtils); + executor, firebaseApp, backendClientReturnsOk, persistedInstallation, mockUtils); assertWithMessage("getId Task failed") .that(Tasks.await(firebaseInstallations.getId())) .isNotEmpty(); - PersistedFidEntry entryValue = persistedFid.readPersistedFidEntryValue(); + PersistedInstallationEntry entryValue = + persistedInstallation.readPersistedInstallationEntryValue(); assertThat(entryValue).hasFid(TEST_FID_1); // Waiting for Task that registers FID on the FIS Servers executor.awaitTermination(500, TimeUnit.MILLISECONDS); // Validate that Persisted FID has a refreshed auth token now - PersistedFidEntry updatedFidEntry = persistedFid.readPersistedFidEntryValue(); - assertThat(updatedFidEntry).hasAuthToken(TEST_AUTH_TOKEN_2); + PersistedInstallationEntry updatedInstallationEntry = + persistedInstallation.readPersistedInstallationEntryValue(); + assertThat(updatedInstallationEntry).hasAuthToken(TEST_AUTH_TOKEN_2); verify(backendClientReturnsOk, never()) .createFirebaseInstallation(TEST_API_KEY, TEST_FID_1, TEST_PROJECT_ID, TEST_APP_ID_1); verify(backendClientReturnsOk, times(1)) @@ -395,23 +415,28 @@ public void testGetId_expiredAuthToken_refreshesAuthToken() throws Exception { @Test public void testGetAuthToken_fidDoesNotExist_successful() throws Exception { - when(mockUtils.isAuthTokenExpired(REGISTERED_FID_ENTRY)).thenReturn(false); + when(mockUtils.isAuthTokenExpired(REGISTERED_INSTALLATION_ENTRY)).thenReturn(false); FirebaseInstallations firebaseInstallations = new FirebaseInstallations( - executor, firebaseApp, backendClientReturnsOk, persistedFid, mockUtils); + executor, firebaseApp, backendClientReturnsOk, persistedInstallation, mockUtils); Tasks.await(firebaseInstallations.getAuthToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH)); - PersistedFidEntry entryValue = persistedFid.readPersistedFidEntryValue(); + PersistedInstallationEntry entryValue = + persistedInstallation.readPersistedInstallationEntryValue(); assertThat(entryValue).hasAuthToken(TEST_AUTH_TOKEN); } @Test - public void testGetAuthToken_PersistedFidError_failure() throws Exception { - when(mockUtils.isAuthTokenExpired(REGISTERED_FID_ENTRY)).thenReturn(false); + public void testGetAuthToken_PersistedInstallationError_failure() throws Exception { + when(mockUtils.isAuthTokenExpired(REGISTERED_INSTALLATION_ENTRY)).thenReturn(false); FirebaseInstallations firebaseInstallations = new FirebaseInstallations( - executor, firebaseApp, backendClientReturnsOk, persistedFidReturnsError, mockUtils); + executor, + firebaseApp, + backendClientReturnsOk, + persistedInstallationReturnsError, + mockUtils); // Expect exception try { @@ -431,12 +456,13 @@ public void testGetAuthToken_PersistedFidError_failure() throws Exception { @Test public void testGetAuthToken_fidExists_successful() throws Exception { - when(mockPersistedFid.readPersistedFidEntryValue()).thenReturn(REGISTERED_FID_ENTRY); - when(mockUtils.isAuthTokenExpired(REGISTERED_FID_ENTRY)).thenReturn(false); + when(mockPersistedInstallation.readPersistedInstallationEntryValue()) + .thenReturn(REGISTERED_INSTALLATION_ENTRY); + when(mockUtils.isAuthTokenExpired(REGISTERED_INSTALLATION_ENTRY)).thenReturn(false); FirebaseInstallations firebaseInstallations = new FirebaseInstallations( - executor, firebaseApp, backendClientReturnsOk, mockPersistedFid, mockUtils); + executor, firebaseApp, backendClientReturnsOk, mockPersistedInstallation, mockUtils); InstallationTokenResult installationTokenResult = Tasks.await( @@ -451,13 +477,13 @@ public void testGetAuthToken_fidExists_successful() throws Exception { @Test public void testGetAuthToken_expiredAuthToken_fetchedNewTokenFromFIS() throws Exception { - persistedFid.insertOrUpdatePersistedFidEntry(EXPIRED_AUTH_TOKEN_ENTRY); + persistedInstallation.insertOrUpdatePersistedInstallationEntry(EXPIRED_AUTH_TOKEN_ENTRY); when(mockUtils.isAuthTokenExpired(EXPIRED_AUTH_TOKEN_ENTRY)).thenReturn(true); when(mockUtils.isAuthTokenExpired(UPDATED_AUTH_TOKEN_ENTRY)).thenReturn(false); FirebaseInstallations firebaseInstallations = new FirebaseInstallations( - executor, firebaseApp, backendClientReturnsOk, persistedFid, mockUtils); + executor, firebaseApp, backendClientReturnsOk, persistedInstallation, mockUtils); InstallationTokenResult installationTokenResult = Tasks.await( @@ -472,14 +498,14 @@ public void testGetAuthToken_expiredAuthToken_fetchedNewTokenFromFIS() throws Ex @Test public void testGetAuthToken_unregisteredFid_fetchedNewTokenFromFIS() throws Exception { - // Update local storage with a unregistered fid entry to validate that getAuthToken calls getId - // to ensure FID registration and returns a valid auth token. - persistedFid.insertOrUpdatePersistedFidEntry(UNREGISTERED_FID_ENTRY); - when(mockUtils.isAuthTokenExpired(REGISTERED_FID_ENTRY)).thenReturn(false); + // Update local storage with a unregistered installation entry to validate that getAuthToken + // calls getId to ensure FID registration and returns a valid auth token. + persistedInstallation.insertOrUpdatePersistedInstallationEntry(UNREGISTERED_INSTALLATION_ENTRY); + when(mockUtils.isAuthTokenExpired(REGISTERED_INSTALLATION_ENTRY)).thenReturn(false); FirebaseInstallations firebaseInstallations = new FirebaseInstallations( - executor, firebaseApp, backendClientReturnsOk, persistedFid, mockUtils); + executor, firebaseApp, backendClientReturnsOk, persistedInstallation, mockUtils); InstallationTokenResult installationTokenResult = Tasks.await( @@ -494,17 +520,18 @@ public void testGetAuthToken_unregisteredFid_fetchedNewTokenFromFIS() throws Exc @Test public void testGetAuthToken_serverError_failure() throws Exception { - when(mockPersistedFid.readPersistedFidEntryValue()).thenReturn(REGISTERED_FID_ENTRY); + when(mockPersistedInstallation.readPersistedInstallationEntryValue()) + .thenReturn(REGISTERED_INSTALLATION_ENTRY); when(backendClientReturnsError.generateAuthToken( anyString(), anyString(), anyString(), anyString())) .thenThrow( new FirebaseInstallationServiceException( "Server Error", FirebaseInstallationServiceException.Status.SERVER_ERROR)); - when(mockUtils.isAuthTokenExpired(REGISTERED_FID_ENTRY)).thenReturn(false); + when(mockUtils.isAuthTokenExpired(REGISTERED_INSTALLATION_ENTRY)).thenReturn(false); FirebaseInstallations firebaseInstallations = new FirebaseInstallations( - executor, firebaseApp, backendClientReturnsError, mockPersistedFid, mockUtils); + executor, firebaseApp, backendClientReturnsError, mockPersistedInstallation, mockUtils); // Expect exception try { @@ -527,13 +554,13 @@ public void testGetAuthToken_multipleCallsDoNotForceRefresh_fetchedNewTokenOnce( // Update local storage with a EXPIRED_AUTH_TOKEN_ENTRY to validate the flow of multiple tasks // triggered simultaneously. Task2 waits for Task1 to complete. On task1 completion, task2 reads // the UPDATED_AUTH_TOKEN_FID_ENTRY generated by Task1. - persistedFid.insertOrUpdatePersistedFidEntry(EXPIRED_AUTH_TOKEN_ENTRY); + persistedInstallation.insertOrUpdatePersistedInstallationEntry(EXPIRED_AUTH_TOKEN_ENTRY); when(mockUtils.isAuthTokenExpired(EXPIRED_AUTH_TOKEN_ENTRY)).thenReturn(true); when(mockUtils.isAuthTokenExpired(UPDATED_AUTH_TOKEN_ENTRY)).thenReturn(false); FirebaseInstallations firebaseInstallations = new FirebaseInstallations( - executor, firebaseApp, backendClientReturnsOk, persistedFid, mockUtils); + executor, firebaseApp, backendClientReturnsOk, persistedInstallation, mockUtils); // Call getAuthToken multiple times with DO_NOT_FORCE_REFRESH option Task task1 = @@ -555,7 +582,7 @@ public void testGetAuthToken_multipleCallsDoNotForceRefresh_fetchedNewTokenOnce( @Test public void testGetAuthToken_multipleCallsForceRefresh_fetchedNewTokenTwice() throws Exception { - persistedFid.insertOrUpdatePersistedFidEntry(REGISTERED_FID_ENTRY); + persistedInstallation.insertOrUpdatePersistedInstallationEntry(REGISTERED_INSTALLATION_ENTRY); // Use a mock ServiceClient for network calls with delay(500ms) to ensure first task is not // completed before the second task starts. Hence, we can test multiple calls to getAuthToken() // and verify one task waits for another task to complete. @@ -584,7 +611,7 @@ public void testGetAuthToken_multipleCallsForceRefresh_fetchedNewTokenTwice() th FirebaseInstallations firebaseInstallations = new FirebaseInstallations( - executor, firebaseApp, backendClientReturnsOk, persistedFid, mockUtils); + executor, firebaseApp, backendClientReturnsOk, persistedInstallation, mockUtils); // Call getAuthToken multiple times with FORCE_REFRESH option. Task task1 = @@ -602,38 +629,41 @@ public void testGetAuthToken_multipleCallsForceRefresh_fetchedNewTokenTwice() th .isEqualTo(TEST_AUTH_TOKEN_3); verify(backendClientReturnsOk, times(1)) .generateAuthToken(TEST_API_KEY, TEST_FID_1, TEST_PROJECT_ID, TEST_REFRESH_TOKEN); - PersistedFidEntry updatedFidEntry = persistedFid.readPersistedFidEntryValue(); - assertThat(updatedFidEntry).hasAuthToken(TEST_AUTH_TOKEN_3); + PersistedInstallationEntry updatedInstallationEntry = + persistedInstallation.readPersistedInstallationEntryValue(); + assertThat(updatedInstallationEntry).hasAuthToken(TEST_AUTH_TOKEN_3); } @Test public void testDelete_registeredFID_successful() throws Exception { - // Update local storage with a registered fid entry - persistedFid.insertOrUpdatePersistedFidEntry(REGISTERED_FID_ENTRY); + // Update local storage with a registered installation entry + persistedInstallation.insertOrUpdatePersistedInstallationEntry(REGISTERED_INSTALLATION_ENTRY); FirebaseInstallations firebaseInstallations = new FirebaseInstallations( - executor, firebaseApp, backendClientReturnsOk, persistedFid, mockUtils); + executor, firebaseApp, backendClientReturnsOk, persistedInstallation, mockUtils); Tasks.await(firebaseInstallations.delete()); - PersistedFidEntry entryValue = persistedFid.readPersistedFidEntryValue(); - assertThat(entryValue).isEqualTo(DEFAULT_PERSISTED_FID_ENTRY); + PersistedInstallationEntry entryValue = + persistedInstallation.readPersistedInstallationEntryValue(); + assertThat(entryValue).isEqualTo(DEFAULT_PERSISTED_INSTALLATION_ENTRY); verify(backendClientReturnsOk, times(1)) .deleteFirebaseInstallation(TEST_API_KEY, TEST_FID_1, TEST_PROJECT_ID, TEST_REFRESH_TOKEN); } @Test public void testDelete_unregisteredFID_successful() throws Exception { - // Update local storage with a unregistered fid entry - persistedFid.insertOrUpdatePersistedFidEntry(UNREGISTERED_FID_ENTRY); + // Update local storage with a unregistered installation entry + persistedInstallation.insertOrUpdatePersistedInstallationEntry(UNREGISTERED_INSTALLATION_ENTRY); FirebaseInstallations firebaseInstallations = new FirebaseInstallations( - executor, firebaseApp, backendClientReturnsOk, persistedFid, mockUtils); + executor, firebaseApp, backendClientReturnsOk, persistedInstallation, mockUtils); Tasks.await(firebaseInstallations.delete()); - PersistedFidEntry entryValue = persistedFid.readPersistedFidEntryValue(); - assertThat(entryValue).isEqualTo(DEFAULT_PERSISTED_FID_ENTRY); + PersistedInstallationEntry entryValue = + persistedInstallation.readPersistedInstallationEntryValue(); + assertThat(entryValue).isEqualTo(DEFAULT_PERSISTED_INSTALLATION_ENTRY); verify(backendClientReturnsOk, never()) .deleteFirebaseInstallation(TEST_API_KEY, TEST_FID_1, TEST_PROJECT_ID, TEST_REFRESH_TOKEN); } @@ -642,23 +672,24 @@ public void testDelete_unregisteredFID_successful() throws Exception { public void testDelete_emptyPersistedFidEntry_successful() throws Exception { FirebaseInstallations firebaseInstallations = new FirebaseInstallations( - executor, firebaseApp, backendClientReturnsOk, persistedFid, mockUtils); + executor, firebaseApp, backendClientReturnsOk, persistedInstallation, mockUtils); Tasks.await(firebaseInstallations.delete()); - PersistedFidEntry entryValue = persistedFid.readPersistedFidEntryValue(); - assertThat(entryValue).isEqualTo(DEFAULT_PERSISTED_FID_ENTRY); + PersistedInstallationEntry entryValue = + persistedInstallation.readPersistedInstallationEntryValue(); + assertThat(entryValue).isEqualTo(DEFAULT_PERSISTED_INSTALLATION_ENTRY); verify(backendClientReturnsOk, never()) .deleteFirebaseInstallation(TEST_API_KEY, TEST_FID_1, TEST_PROJECT_ID, TEST_REFRESH_TOKEN); } @Test public void testDelete_serverError_failure() throws Exception { - // Update local storage with a registered fid entry - persistedFid.insertOrUpdatePersistedFidEntry(REGISTERED_FID_ENTRY); + // Update local storage with a registered installation entry + persistedInstallation.insertOrUpdatePersistedInstallationEntry(REGISTERED_INSTALLATION_ENTRY); FirebaseInstallations firebaseInstallations = new FirebaseInstallations( - executor, firebaseApp, backendClientReturnsError, persistedFid, mockUtils); + executor, firebaseApp, backendClientReturnsError, persistedInstallation, mockUtils); // Expect exception try { @@ -672,8 +703,9 @@ public void testDelete_serverError_failure() throws Exception { assertWithMessage("Exception status doesn't match") .that(((FirebaseInstallationsException) expected.getCause()).getStatus()) .isEqualTo(FirebaseInstallationsException.Status.SDK_INTERNAL_ERROR); - PersistedFidEntry entryValue = persistedFid.readPersistedFidEntryValue(); - assertThat(entryValue).isEqualTo(REGISTERED_FID_ENTRY); + PersistedInstallationEntry entryValue = + persistedInstallation.readPersistedInstallationEntryValue(); + assertThat(entryValue).isEqualTo(REGISTERED_INSTALLATION_ENTRY); } } } diff --git a/firebase-installations/src/androidTest/java/com/google/firebase/installations/FisAndroidTestConstants.java b/firebase-installations/src/androidTest/java/com/google/firebase/installations/FisAndroidTestConstants.java index ddbfcd982e2..d94cdcc214c 100644 --- a/firebase-installations/src/androidTest/java/com/google/firebase/installations/FisAndroidTestConstants.java +++ b/firebase-installations/src/androidTest/java/com/google/firebase/installations/FisAndroidTestConstants.java @@ -14,7 +14,7 @@ package com.google.firebase.installations; -import com.google.firebase.installations.local.PersistedFidEntry; +import com.google.firebase.installations.local.PersistedInstallationEntry; import com.google.firebase.installations.remote.InstallationResponse; public final class FisAndroidTestConstants { @@ -42,8 +42,8 @@ public final class FisAndroidTestConstants { public static final long TEST_CREATION_TIMESTAMP_1 = 2000L; public static final long TEST_CREATION_TIMESTAMP_2 = 2L; - public static final PersistedFidEntry DEFAULT_PERSISTED_FID_ENTRY = - PersistedFidEntry.builder().build(); + public static final PersistedInstallationEntry DEFAULT_PERSISTED_INSTALLATION_ENTRY = + PersistedInstallationEntry.builder().build(); public static final InstallationResponse TEST_INSTALLATION_RESPONSE = InstallationResponse.builder() .setUri("/projects/" + TEST_PROJECT_ID + "/installations/" + TEST_FID_1) diff --git a/firebase-installations/src/androidTest/java/com/google/firebase/installations/local/PersistedFidEntrySubject.java b/firebase-installations/src/androidTest/java/com/google/firebase/installations/local/PersistedInstallationEntrySubject.java similarity index 65% rename from firebase-installations/src/androidTest/java/com/google/firebase/installations/local/PersistedFidEntrySubject.java rename to firebase-installations/src/androidTest/java/com/google/firebase/installations/local/PersistedInstallationEntrySubject.java index 48586508823..84c738ef42c 100644 --- a/firebase-installations/src/androidTest/java/com/google/firebase/installations/local/PersistedFidEntrySubject.java +++ b/firebase-installations/src/androidTest/java/com/google/firebase/installations/local/PersistedInstallationEntrySubject.java @@ -18,37 +18,40 @@ import com.google.common.truth.FailureMetadata; import com.google.common.truth.Subject; -import com.google.firebase.installations.local.PersistedFid.RegistrationStatus; +import com.google.firebase.installations.local.PersistedInstallation.RegistrationStatus; import org.checkerframework.checker.nullness.compatqual.NullableDecl; -public final class PersistedFidEntrySubject extends Subject { +public final class PersistedInstallationEntrySubject extends Subject { // User-defined entry point - public static PersistedFidEntrySubject assertThat( - @NullableDecl PersistedFidEntry persistedFidEntry) { - return assertAbout(PERSISTED_FID_ENTRY_SUBJECT_FACTORY).that(persistedFidEntry); + public static PersistedInstallationEntrySubject assertThat( + @NullableDecl PersistedInstallationEntry persistedInstallationEntry) { + return assertAbout(PERSISTED_INSTALLATION_ENTRY_SUBJECT_FACTORY) + .that(persistedInstallationEntry); } // Static method for getting the subject factory (for use with assertAbout()) - public static Subject.Factory persistedFidEntry() { - return PERSISTED_FID_ENTRY_SUBJECT_FACTORY; + public static Subject.Factory + persistedInstallationEntry() { + return PERSISTED_INSTALLATION_ENTRY_SUBJECT_FACTORY; } - // Boiler-plate Subject.Factory for EmployeeSubject - private static final Subject.Factory - PERSISTED_FID_ENTRY_SUBJECT_FACTORY = PersistedFidEntrySubject::new; + // Boiler-plate Subject.Factory for PersistedInstallationEntrySubject + private static final Subject.Factory< + PersistedInstallationEntrySubject, PersistedInstallationEntry> + PERSISTED_INSTALLATION_ENTRY_SUBJECT_FACTORY = PersistedInstallationEntrySubject::new; - private final PersistedFidEntry actual; + private final PersistedInstallationEntry actual; /** * Constructor for use by subclasses. If you want to create an instance of this class itself, call - * {@link Subject#check(String, PersistedFidEntry ..) check(...)}{@code .that(actual)}. + * {@link Subject#check(String, PersistedInstallationEntry ..) check(...)}{@code .that(actual)}. * * @param metadata * @param actual */ - protected PersistedFidEntrySubject( - FailureMetadata metadata, @NullableDecl PersistedFidEntry actual) { + protected PersistedInstallationEntrySubject( + FailureMetadata metadata, @NullableDecl PersistedInstallationEntry actual) { super(metadata, actual); this.actual = actual; } diff --git a/firebase-installations/src/androidTest/java/com/google/firebase/installations/local/PersistedFidTest.java b/firebase-installations/src/androidTest/java/com/google/firebase/installations/local/PersistedInstallationTest.java similarity index 69% rename from firebase-installations/src/androidTest/java/com/google/firebase/installations/local/PersistedFidTest.java rename to firebase-installations/src/androidTest/java/com/google/firebase/installations/local/PersistedInstallationTest.java index f00b9447bdb..a27e1885924 100644 --- a/firebase-installations/src/androidTest/java/com/google/firebase/installations/local/PersistedFidTest.java +++ b/firebase-installations/src/androidTest/java/com/google/firebase/installations/local/PersistedInstallationTest.java @@ -14,7 +14,7 @@ package com.google.firebase.installations.local; -import static com.google.firebase.installations.FisAndroidTestConstants.DEFAULT_PERSISTED_FID_ENTRY; +import static com.google.firebase.installations.FisAndroidTestConstants.DEFAULT_PERSISTED_INSTALLATION_ENTRY; import static com.google.firebase.installations.FisAndroidTestConstants.TEST_APP_ID_1; import static com.google.firebase.installations.FisAndroidTestConstants.TEST_APP_ID_2; import static com.google.firebase.installations.FisAndroidTestConstants.TEST_AUTH_TOKEN; @@ -23,27 +23,27 @@ import static com.google.firebase.installations.FisAndroidTestConstants.TEST_FID_1; import static com.google.firebase.installations.FisAndroidTestConstants.TEST_REFRESH_TOKEN; import static com.google.firebase.installations.FisAndroidTestConstants.TEST_TOKEN_EXPIRATION_TIMESTAMP; -import static com.google.firebase.installations.local.PersistedFidEntrySubject.assertThat; +import static com.google.firebase.installations.local.PersistedInstallationEntrySubject.assertThat; import static org.junit.Assert.assertTrue; import androidx.test.core.app.ApplicationProvider; import androidx.test.runner.AndroidJUnit4; import com.google.firebase.FirebaseApp; import com.google.firebase.FirebaseOptions; -import com.google.firebase.installations.local.PersistedFid.RegistrationStatus; +import com.google.firebase.installations.local.PersistedInstallation.RegistrationStatus; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -/** Instrumented tests for {@link PersistedFid} */ +/** Instrumented tests for {@link PersistedInstallation} */ @RunWith(AndroidJUnit4.class) -public class PersistedFidTest { +public class PersistedInstallationTest { private FirebaseApp firebaseApp0; private FirebaseApp firebaseApp1; - private PersistedFid persistedFid0; - private PersistedFid persistedFid1; + private PersistedInstallation persistedInstallation0; + private PersistedInstallation persistedInstallation1; @Before public void setUp() { @@ -57,36 +57,39 @@ public void setUp() { ApplicationProvider.getApplicationContext(), new FirebaseOptions.Builder().setApplicationId(TEST_APP_ID_2).build(), "firebase_app_1"); - persistedFid0 = new PersistedFid(firebaseApp0); - persistedFid1 = new PersistedFid(firebaseApp1); + persistedInstallation0 = new PersistedInstallation(firebaseApp0); + persistedInstallation1 = new PersistedInstallation(firebaseApp1); } @After public void cleanUp() throws Exception { - persistedFid0.clear(); - persistedFid1.clear(); + persistedInstallation0.clear(); + persistedInstallation1.clear(); } @Test - public void testReadPersistedFidEntry_Null() { - assertThat(persistedFid0.readPersistedFidEntryValue()).isEqualTo(DEFAULT_PERSISTED_FID_ENTRY); - assertThat(persistedFid1.readPersistedFidEntryValue()).isEqualTo(DEFAULT_PERSISTED_FID_ENTRY); + public void testReadPersistedInstallationEntry_Null() { + assertThat(persistedInstallation0.readPersistedInstallationEntryValue()) + .isEqualTo(DEFAULT_PERSISTED_INSTALLATION_ENTRY); + assertThat(persistedInstallation1.readPersistedInstallationEntryValue()) + .isEqualTo(DEFAULT_PERSISTED_INSTALLATION_ENTRY); } @Test - public void testUpdateAndReadPersistedFidEntry_successful() throws Exception { - // Insert Persisted Fid Entry with Unregistered status in Shared Prefs + public void testUpdateAndReadPersistedInstallationEntry_successful() throws Exception { + // Insert Persisted Installation Entry with Unregistered status in Shared Prefs assertTrue( - persistedFid0.insertOrUpdatePersistedFidEntry( - PersistedFidEntry.builder() + persistedInstallation0.insertOrUpdatePersistedInstallationEntry( + PersistedInstallationEntry.builder() .setFirebaseInstallationId(TEST_FID_1) .setAuthToken(TEST_AUTH_TOKEN) .setRefreshToken(TEST_REFRESH_TOKEN) - .setRegistrationStatus(PersistedFid.RegistrationStatus.UNREGISTERED) + .setRegistrationStatus(PersistedInstallation.RegistrationStatus.UNREGISTERED) .setTokenCreationEpochInSecs(TEST_CREATION_TIMESTAMP_1) .setExpiresInSecs(TEST_TOKEN_EXPIRATION_TIMESTAMP) .build())); - PersistedFidEntry entryValue = persistedFid0.readPersistedFidEntryValue(); + PersistedInstallationEntry entryValue = + persistedInstallation0.readPersistedInstallationEntryValue(); // Validate insertion was successful assertThat(entryValue).hasFid(TEST_FID_1); @@ -98,16 +101,16 @@ public void testUpdateAndReadPersistedFidEntry_successful() throws Exception { // Update Persisted Fid Entry with Registered status in Shared Prefs assertTrue( - persistedFid0.insertOrUpdatePersistedFidEntry( - PersistedFidEntry.builder() + persistedInstallation0.insertOrUpdatePersistedInstallationEntry( + PersistedInstallationEntry.builder() .setFirebaseInstallationId(TEST_FID_1) .setAuthToken(TEST_AUTH_TOKEN) .setRefreshToken(TEST_REFRESH_TOKEN) - .setRegistrationStatus(PersistedFid.RegistrationStatus.REGISTERED) + .setRegistrationStatus(PersistedInstallation.RegistrationStatus.REGISTERED) .setTokenCreationEpochInSecs(TEST_CREATION_TIMESTAMP_2) .setExpiresInSecs(TEST_TOKEN_EXPIRATION_TIMESTAMP) .build())); - entryValue = persistedFid0.readPersistedFidEntryValue(); + entryValue = persistedInstallation0.readPersistedInstallationEntryValue(); // Validate update was successful assertThat(entryValue).hasFid(TEST_FID_1); diff --git a/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java b/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java index 2f57e9e8f1a..c074ba69712 100644 --- a/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java +++ b/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java @@ -23,9 +23,9 @@ import com.google.android.gms.tasks.TaskCompletionSource; import com.google.android.gms.tasks.Tasks; import com.google.firebase.FirebaseApp; -import com.google.firebase.installations.local.PersistedFid; -import com.google.firebase.installations.local.PersistedFid.RegistrationStatus; -import com.google.firebase.installations.local.PersistedFidEntry; +import com.google.firebase.installations.local.PersistedInstallation; +import com.google.firebase.installations.local.PersistedInstallation.RegistrationStatus; +import com.google.firebase.installations.local.PersistedInstallationEntry; import com.google.firebase.installations.remote.FirebaseInstallationServiceClient; import com.google.firebase.installations.remote.FirebaseInstallationServiceException; import com.google.firebase.installations.remote.InstallationResponse; @@ -52,7 +52,7 @@ public class FirebaseInstallations implements FirebaseInstallationsApi { private final FirebaseApp firebaseApp; private final FirebaseInstallationServiceClient serviceClient; - private final PersistedFid persistedFid; + private final PersistedInstallation persistedInstallation; private final ExecutorService executor; private final Utils utils; private final Object lock = new Object(); @@ -69,7 +69,7 @@ public class FirebaseInstallations implements FirebaseInstallationsApi { new ThreadPoolExecutor(0, 1, 30L, TimeUnit.SECONDS, new LinkedBlockingQueue<>()), firebaseApp, new FirebaseInstallationServiceClient(firebaseApp.getApplicationContext()), - new PersistedFid(firebaseApp), + new PersistedInstallation(firebaseApp), new Utils(DefaultClock.getInstance())); } @@ -77,12 +77,12 @@ public class FirebaseInstallations implements FirebaseInstallationsApi { ExecutorService executor, FirebaseApp firebaseApp, FirebaseInstallationServiceClient serviceClient, - PersistedFid persistedFid, + PersistedInstallation persistedInstallation, Utils utils) { this.firebaseApp = firebaseApp; this.serviceClient = serviceClient; this.executor = executor; - this.persistedFid = persistedFid; + this.persistedInstallation = persistedInstallation; this.utils = utils; } @@ -184,12 +184,13 @@ private Task addGetAuthTokenListener( return taskCompletionSource.getTask(); } - private void triggerOnStateReached(PersistedFidEntry persistedFidEntry) { + private void triggerOnStateReached(PersistedInstallationEntry persistedInstallationEntry) { synchronized (lock) { Iterator it = listeners.iterator(); while (it.hasNext()) { StateListener l = it.next(); - boolean doneListening = l.onStateReached(persistedFidEntry, shouldRefreshAuthToken); + boolean doneListening = + l.onStateReached(persistedInstallationEntry, shouldRefreshAuthToken); if (doneListening) { it.remove(); } @@ -197,12 +198,13 @@ private void triggerOnStateReached(PersistedFidEntry persistedFidEntry) { } } - private void triggerOnException(PersistedFidEntry persistedFidEntry, Exception exception) { + private void triggerOnException( + PersistedInstallationEntry persistedInstallationEntry, Exception exception) { synchronized (lock) { Iterator it = listeners.iterator(); while (it.hasNext()) { StateListener l = it.next(); - boolean doneListening = l.onException(persistedFidEntry, exception); + boolean doneListening = l.onException(persistedInstallationEntry, exception); if (doneListening) { it.remove(); } @@ -212,21 +214,22 @@ private void triggerOnException(PersistedFidEntry persistedFidEntry, Exception e private final void doRegistration() { try { - PersistedFidEntry persistedFidEntry = persistedFid.readPersistedFidEntryValue(); + PersistedInstallationEntry persistedInstallationEntry = + persistedInstallation.readPersistedInstallationEntryValue(); // New FID needs to be created - if (persistedFidEntry.isErrored() || persistedFidEntry.isNotGenerated()) { + if (persistedInstallationEntry.isErrored() || persistedInstallationEntry.isNotGenerated()) { String fid = utils.createRandomFid(); persistFid(fid); - persistedFidEntry = persistedFid.readPersistedFidEntryValue(); + persistedInstallationEntry = persistedInstallation.readPersistedInstallationEntryValue(); } - triggerOnStateReached(persistedFidEntry); + triggerOnStateReached(persistedInstallationEntry); // FID needs to be registered - if (persistedFidEntry.isUnregistered()) { - registerAndSaveFid(persistedFidEntry); - persistedFidEntry = persistedFid.readPersistedFidEntryValue(); + if (persistedInstallationEntry.isUnregistered()) { + registerAndSaveFid(persistedInstallationEntry); + persistedInstallationEntry = persistedInstallation.readPersistedInstallationEntryValue(); // Newly registered Fid will have valid auth token. No refresh required. synchronized (lock) { shouldRefreshAuthToken = false; @@ -236,7 +239,7 @@ private final void doRegistration() { // Don't notify the listeners at this point; we might as well make ure the auth token is up // to date before letting them know. - boolean needRefresh = utils.isAuthTokenExpired(persistedFidEntry); + boolean needRefresh = utils.isAuthTokenExpired(persistedInstallationEntry); if (!needRefresh) { synchronized (lock) { needRefresh = shouldRefreshAuthToken; @@ -245,30 +248,31 @@ private final void doRegistration() { // Refresh Auth token if needed if (needRefresh) { - fetchAuthTokenFromServer(persistedFidEntry); - persistedFidEntry = persistedFid.readPersistedFidEntryValue(); + fetchAuthTokenFromServer(persistedInstallationEntry); + persistedInstallationEntry = persistedInstallation.readPersistedInstallationEntryValue(); synchronized (lock) { shouldRefreshAuthToken = false; } } - triggerOnStateReached(persistedFidEntry); + triggerOnStateReached(persistedInstallationEntry); } catch (Exception e) { - PersistedFidEntry persistedFidEntry = persistedFid.readPersistedFidEntryValue(); - PersistedFidEntry errorFidEntry = - persistedFidEntry + PersistedInstallationEntry persistedInstallationEntry = + persistedInstallation.readPersistedInstallationEntryValue(); + PersistedInstallationEntry errorInstallationEntry = + persistedInstallationEntry .toBuilder() .setRegistrationStatus(RegistrationStatus.REGISTER_ERROR) .build(); - persistedFid.insertOrUpdatePersistedFidEntry(errorFidEntry); - triggerOnException(errorFidEntry, e); + persistedInstallation.insertOrUpdatePersistedInstallationEntry(errorInstallationEntry); + triggerOnException(errorInstallationEntry, e); } } private void persistFid(String fid) throws FirebaseInstallationsException { boolean firstUpdateCacheResult = - persistedFid.insertOrUpdatePersistedFidEntry( - PersistedFidEntry.builder() + persistedInstallation.insertOrUpdatePersistedInstallationEntry( + PersistedInstallationEntry.builder() .setFirebaseInstallationId(fid) .setRegistrationStatus(RegistrationStatus.UNREGISTERED) .build()); @@ -281,7 +285,7 @@ private void persistFid(String fid) throws FirebaseInstallationsException { } /** Registers the created Fid with FIS servers and update the shared prefs. */ - private Void registerAndSaveFid(PersistedFidEntry persistedFidEntry) + private Void registerAndSaveFid(PersistedInstallationEntry persistedInstallationEntry) throws FirebaseInstallationsException { try { long creationTime = utils.currentTimeInSecs(); @@ -289,11 +293,11 @@ private Void registerAndSaveFid(PersistedFidEntry persistedFidEntry) InstallationResponse installationResponse = serviceClient.createFirebaseInstallation( /*apiKey= */ firebaseApp.getOptions().getApiKey(), - /*fid= */ persistedFidEntry.getFirebaseInstallationId(), + /*fid= */ persistedInstallationEntry.getFirebaseInstallationId(), /*projectID= */ firebaseApp.getOptions().getProjectId(), /*appId= */ getApplicationId()); - persistedFid.insertOrUpdatePersistedFidEntry( - PersistedFidEntry.builder() + persistedInstallation.insertOrUpdatePersistedInstallationEntry( + PersistedInstallationEntry.builder() .setFirebaseInstallationId(installationResponse.getFid()) .setRegistrationStatus(RegistrationStatus.REGISTERED) .setAuthToken(installationResponse.getAuthToken().getToken()) @@ -310,23 +314,23 @@ private Void registerAndSaveFid(PersistedFidEntry persistedFidEntry) } /** Calls the FIS servers to generate an auth token for this Firebase installation. */ - private InstallationTokenResult fetchAuthTokenFromServer(PersistedFidEntry persistedFidEntry) - throws FirebaseInstallationsException { + private InstallationTokenResult fetchAuthTokenFromServer( + PersistedInstallationEntry persistedInstallationEntry) throws FirebaseInstallationsException { try { long creationTime = utils.currentTimeInSecs(); InstallationTokenResult tokenResult = serviceClient.generateAuthToken( /*apiKey= */ firebaseApp.getOptions().getApiKey(), - /*fid= */ persistedFidEntry.getFirebaseInstallationId(), + /*fid= */ persistedInstallationEntry.getFirebaseInstallationId(), /*projectID= */ firebaseApp.getOptions().getProjectId(), - /*refreshToken= */ persistedFidEntry.getRefreshToken()); + /*refreshToken= */ persistedInstallationEntry.getRefreshToken()); - persistedFid.insertOrUpdatePersistedFidEntry( - PersistedFidEntry.builder() - .setFirebaseInstallationId(persistedFidEntry.getFirebaseInstallationId()) + persistedInstallation.insertOrUpdatePersistedInstallationEntry( + PersistedInstallationEntry.builder() + .setFirebaseInstallationId(persistedInstallationEntry.getFirebaseInstallationId()) .setRegistrationStatus(RegistrationStatus.REGISTERED) .setAuthToken(tokenResult.getToken()) - .setRefreshToken(persistedFidEntry.getRefreshToken()) + .setRefreshToken(persistedInstallationEntry.getRefreshToken()) .setExpiresInSecs(tokenResult.getTokenExpirationTimestamp()) .setTokenCreationEpochInSecs(creationTime) .build()); @@ -345,16 +349,17 @@ private InstallationTokenResult fetchAuthTokenFromServer(PersistedFidEntry persi */ private Void deleteFirebaseInstallationId() throws FirebaseInstallationsException { - PersistedFidEntry persistedFidEntry = persistedFid.readPersistedFidEntryValue(); + PersistedInstallationEntry persistedInstallationEntry = + persistedInstallation.readPersistedInstallationEntryValue(); - if (persistedFidEntry.isRegistered()) { + if (persistedInstallationEntry.isRegistered()) { // Call the FIS servers to delete this Firebase Installation Id. try { serviceClient.deleteFirebaseInstallation( firebaseApp.getOptions().getApiKey(), - persistedFidEntry.getFirebaseInstallationId(), + persistedInstallationEntry.getFirebaseInstallationId(), firebaseApp.getOptions().getProjectId(), - persistedFidEntry.getRefreshToken()); + persistedInstallationEntry.getRefreshToken()); } catch (FirebaseInstallationServiceException exception) { throw new FirebaseInstallationsException( @@ -363,7 +368,7 @@ private Void deleteFirebaseInstallationId() throws FirebaseInstallationsExceptio } } - persistedFid.clear(); + persistedInstallation.clear(); return null; } } diff --git a/firebase-installations/src/main/java/com/google/firebase/installations/GetAuthTokenListener.java b/firebase-installations/src/main/java/com/google/firebase/installations/GetAuthTokenListener.java index 008daadbe65..d0898aabd5a 100644 --- a/firebase-installations/src/main/java/com/google/firebase/installations/GetAuthTokenListener.java +++ b/firebase-installations/src/main/java/com/google/firebase/installations/GetAuthTokenListener.java @@ -15,7 +15,7 @@ package com.google.firebase.installations; import com.google.android.gms.tasks.TaskCompletionSource; -import com.google.firebase.installations.local.PersistedFidEntry; +import com.google.firebase.installations.local.PersistedInstallationEntry; class GetAuthTokenListener implements StateListener { private final Utils utils; @@ -29,16 +29,16 @@ public GetAuthTokenListener( @Override public boolean onStateReached( - PersistedFidEntry persistedFidEntry, boolean shouldRefreshAuthToken) { + PersistedInstallationEntry persistedInstallationEntry, boolean shouldRefreshAuthToken) { // AuthTokenListener state is reached when FID is registered and has a valid auth token - if (persistedFidEntry.isRegistered() - && !utils.isAuthTokenExpired(persistedFidEntry) + if (persistedInstallationEntry.isRegistered() + && !utils.isAuthTokenExpired(persistedInstallationEntry) && !shouldRefreshAuthToken) { resultTaskCompletionSource.setResult( InstallationTokenResult.builder() - .setToken(persistedFidEntry.getAuthToken()) - .setTokenExpirationTimestamp(persistedFidEntry.getExpiresInSecs()) - .setTokenCreationTimestamp(persistedFidEntry.getTokenCreationEpochInSecs()) + .setToken(persistedInstallationEntry.getAuthToken()) + .setTokenExpirationTimestamp(persistedInstallationEntry.getExpiresInSecs()) + .setTokenCreationTimestamp(persistedInstallationEntry.getTokenCreationEpochInSecs()) .build()); return true; } @@ -46,8 +46,9 @@ public boolean onStateReached( } @Override - public boolean onException(PersistedFidEntry persistedFidEntry, Exception exception) { - if (persistedFidEntry.isErrored()) { + public boolean onException( + PersistedInstallationEntry persistedInstallationEntry, Exception exception) { + if (persistedInstallationEntry.isErrored()) { resultTaskCompletionSource.trySetException(exception); return true; } diff --git a/firebase-installations/src/main/java/com/google/firebase/installations/GetIdListener.java b/firebase-installations/src/main/java/com/google/firebase/installations/GetIdListener.java index 2e24b97cc07..38134cc6217 100644 --- a/firebase-installations/src/main/java/com/google/firebase/installations/GetIdListener.java +++ b/firebase-installations/src/main/java/com/google/firebase/installations/GetIdListener.java @@ -15,7 +15,7 @@ package com.google.firebase.installations; import com.google.android.gms.tasks.TaskCompletionSource; -import com.google.firebase.installations.local.PersistedFidEntry; +import com.google.firebase.installations.local.PersistedInstallationEntry; class GetIdListener implements StateListener { final TaskCompletionSource taskCompletionSource; @@ -25,17 +25,19 @@ public GetIdListener(TaskCompletionSource taskCompletionSource) { } @Override - public boolean onStateReached(PersistedFidEntry persistedFidEntry, boolean unused) { - if (persistedFidEntry.isUnregistered() || persistedFidEntry.isRegistered()) { - taskCompletionSource.trySetResult(persistedFidEntry.getFirebaseInstallationId()); + public boolean onStateReached( + PersistedInstallationEntry persistedInstallationEntry, boolean unused) { + if (persistedInstallationEntry.isUnregistered() || persistedInstallationEntry.isRegistered()) { + taskCompletionSource.trySetResult(persistedInstallationEntry.getFirebaseInstallationId()); return true; } return false; } @Override - public boolean onException(PersistedFidEntry persistedFidEntry, Exception exception) { - if (persistedFidEntry.isErrored()) { + public boolean onException( + PersistedInstallationEntry persistedInstallationEntry, Exception exception) { + if (persistedInstallationEntry.isErrored()) { taskCompletionSource.trySetException(exception); return true; } diff --git a/firebase-installations/src/main/java/com/google/firebase/installations/StateListener.java b/firebase-installations/src/main/java/com/google/firebase/installations/StateListener.java index a9691f63d18..d9570835adf 100644 --- a/firebase-installations/src/main/java/com/google/firebase/installations/StateListener.java +++ b/firebase-installations/src/main/java/com/google/firebase/installations/StateListener.java @@ -14,18 +14,19 @@ package com.google.firebase.installations; -import com.google.firebase.installations.local.PersistedFidEntry; +import com.google.firebase.installations.local.PersistedInstallationEntry; interface StateListener { /** - * Returns {@code true} if the defined {@link PersistedFidEntry} state is reached, {@code false} - * otherwise. + * Returns {@code true} if the defined {@link PersistedInstallationEntry} state is reached, {@code + * false} otherwise. */ - boolean onStateReached(PersistedFidEntry persistedFidEntry, boolean shouldRefreshAuthToken); + boolean onStateReached( + PersistedInstallationEntry persistedInstallationEntry, boolean shouldRefreshAuthToken); /** * Returns {@code true} if an exception is thrown while registering a Firebase Installation, * {@code false} otherwise. */ - boolean onException(PersistedFidEntry persistedFidEntry, Exception exception); + boolean onException(PersistedInstallationEntry persistedInstallationEntry, Exception exception); } diff --git a/firebase-installations/src/main/java/com/google/firebase/installations/Utils.java b/firebase-installations/src/main/java/com/google/firebase/installations/Utils.java index 1a3477e9894..03fd022befd 100644 --- a/firebase-installations/src/main/java/com/google/firebase/installations/Utils.java +++ b/firebase-installations/src/main/java/com/google/firebase/installations/Utils.java @@ -16,7 +16,7 @@ import androidx.annotation.NonNull; import com.google.android.gms.common.util.Clock; -import com.google.firebase.installations.local.PersistedFidEntry; +import com.google.firebase.installations.local.PersistedInstallationEntry; import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.util.UUID; @@ -52,8 +52,9 @@ class Utils { * Checks if the FIS Auth token is expired or going to expire in next 1 hour {@link * #AUTH_TOKEN_EXPIRATION_BUFFER_IN_SECS}. */ - public boolean isAuthTokenExpired(PersistedFidEntry persistedFidEntry) { - return persistedFidEntry.getTokenCreationEpochInSecs() + persistedFidEntry.getExpiresInSecs() + public boolean isAuthTokenExpired(PersistedInstallationEntry persistedInstallationEntry) { + return persistedInstallationEntry.getTokenCreationEpochInSecs() + + persistedInstallationEntry.getExpiresInSecs() > currentTimeInSecs() + AUTH_TOKEN_EXPIRATION_BUFFER_IN_SECS; } diff --git a/firebase-installations/src/main/java/com/google/firebase/installations/local/PersistedFid.java b/firebase-installations/src/main/java/com/google/firebase/installations/local/PersistedInstallation.java similarity index 79% rename from firebase-installations/src/main/java/com/google/firebase/installations/local/PersistedFid.java rename to firebase-installations/src/main/java/com/google/firebase/installations/local/PersistedInstallation.java index 808b277c467..aa47c16d8b1 100644 --- a/firebase-installations/src/main/java/com/google/firebase/installations/local/PersistedFid.java +++ b/firebase-installations/src/main/java/com/google/firebase/installations/local/PersistedInstallation.java @@ -26,36 +26,36 @@ * A layer that locally persists a few Firebase Installation attributes on top the Firebase * Installation API. */ -public class PersistedFid { +public class PersistedInstallation { // Registration Status of each persisted fid entry // NOTE: never change the ordinal of the enum values because the enum values are stored in shared // prefs as their ordinal numbers. public enum RegistrationStatus { /** - * {@link PersistedFidEntry} default registration status. Next state: UNREGISTERED - A new FID - * is created and persisted locally before registering with FIS servers. + * {@link PersistedInstallationEntry} default registration status. Next state: UNREGISTERED - A + * new FID is created and persisted locally before registering with FIS servers. */ NOT_GENERATED, /** - * {@link PersistedFidEntry} is not synced with FIS servers. Next state: REGISTERED - If FID - * registration is successful. REGISTER_ERROR - If FID registration or refresh auth token + * {@link PersistedInstallationEntry} is not synced with FIS servers. Next state: REGISTERED - + * If FID registration is successful. REGISTER_ERROR - If FID registration or refresh auth token * failed. */ UNREGISTERED, /** - * {@link PersistedFidEntry} is synced to FIS servers. Next state: REGISTER_ERROR - If FID - * registration or refresh auth token failed. + * {@link PersistedInstallationEntry} is synced to FIS servers. Next state: REGISTER_ERROR - If + * FID registration or refresh auth token failed. */ REGISTERED, /** - * {@link PersistedFidEntry} is in error state when an exception is thrown while syncing with - * FIS server. Next state: UNREGISTERED - A new FID is created and persisted locally before - * registering with FIS servers. + * {@link PersistedInstallationEntry} is in error state when an exception is thrown while + * syncing with FIS server. Next state: UNREGISTERED - A new FID is created and persisted + * locally before registering with FIS servers. */ REGISTER_ERROR, } - private static final String SHARED_PREFS_NAME = "PersistedFid"; + private static final String SHARED_PREFS_NAME = "PersistedInstallation"; private static final String FIREBASE_INSTALLATION_ID_KEY = "Fid"; private static final String AUTH_TOKEN_KEY = "AuthToken"; @@ -78,7 +78,7 @@ public enum RegistrationStatus { private final String persistenceKey; - public PersistedFid(@NonNull FirebaseApp firebaseApp) { + public PersistedInstallation(@NonNull FirebaseApp firebaseApp) { // Different FirebaseApp in the same Android application should have the same application // context and same dir path prefs = @@ -89,7 +89,7 @@ public PersistedFid(@NonNull FirebaseApp firebaseApp) { } @NonNull - public PersistedFidEntry readPersistedFidEntryValue() { + public PersistedInstallationEntry readPersistedInstallationEntryValue() { synchronized (prefs) { String fid = prefs.getString(getSharedPreferencesKey(FIREBASE_INSTALLATION_ID_KEY), null); int status = prefs.getInt(getSharedPreferencesKey(PERSISTED_STATUS_KEY), -1); @@ -100,9 +100,9 @@ public PersistedFidEntry readPersistedFidEntryValue() { long expiresIn = prefs.getLong(getSharedPreferencesKey(EXPIRES_IN_SECONDS_KEY), 0); if (fid == null || !(status >= 0 && status < RegistrationStatus.values().length)) { - return PersistedFidEntry.builder().build(); + return PersistedInstallationEntry.builder().build(); } - return PersistedFidEntry.builder() + return PersistedInstallationEntry.builder() .setFirebaseInstallationId(fid) .setRegistrationStatus(RegistrationStatus.values()[status]) .setAuthToken(authToken) @@ -114,7 +114,8 @@ public PersistedFidEntry readPersistedFidEntryValue() { } @NonNull - public boolean insertOrUpdatePersistedFidEntry(@NonNull PersistedFidEntry entryValue) { + public boolean insertOrUpdatePersistedInstallationEntry( + @NonNull PersistedInstallationEntry entryValue) { synchronized (prefs) { SharedPreferences.Editor editor = prefs.edit(); editor.putString( diff --git a/firebase-installations/src/main/java/com/google/firebase/installations/local/PersistedFidEntry.java b/firebase-installations/src/main/java/com/google/firebase/installations/local/PersistedInstallationEntry.java similarity index 63% rename from firebase-installations/src/main/java/com/google/firebase/installations/local/PersistedFidEntry.java rename to firebase-installations/src/main/java/com/google/firebase/installations/local/PersistedInstallationEntry.java index 4019967cdb6..e7d66ae914f 100644 --- a/firebase-installations/src/main/java/com/google/firebase/installations/local/PersistedFidEntry.java +++ b/firebase-installations/src/main/java/com/google/firebase/installations/local/PersistedInstallationEntry.java @@ -19,17 +19,17 @@ import com.google.auto.value.AutoValue; /** - * This class represents a persisted fid entry in {@link PersistedFid}, which contains a few - * Firebase Installation attributes and the persisted status of this entry. + * This class represents a persisted fid entry in {@link PersistedInstallation}, which contains a + * few Firebase Installation attributes and the persisted status of this entry. */ @AutoValue -public abstract class PersistedFidEntry { +public abstract class PersistedInstallationEntry { @Nullable public abstract String getFirebaseInstallationId(); @NonNull - public abstract PersistedFid.RegistrationStatus getRegistrationStatus(); + public abstract PersistedInstallation.RegistrationStatus getRegistrationStatus(); @Nullable public abstract String getAuthToken(); @@ -42,30 +42,30 @@ public abstract class PersistedFidEntry { public abstract long getTokenCreationEpochInSecs(); public boolean isRegistered() { - return getRegistrationStatus() == PersistedFid.RegistrationStatus.REGISTERED; + return getRegistrationStatus() == PersistedInstallation.RegistrationStatus.REGISTERED; } public boolean isErrored() { - return getRegistrationStatus() == PersistedFid.RegistrationStatus.REGISTER_ERROR; + return getRegistrationStatus() == PersistedInstallation.RegistrationStatus.REGISTER_ERROR; } public boolean isUnregistered() { - return getRegistrationStatus() == PersistedFid.RegistrationStatus.UNREGISTERED; + return getRegistrationStatus() == PersistedInstallation.RegistrationStatus.UNREGISTERED; } public boolean isNotGenerated() { - return getRegistrationStatus() == PersistedFid.RegistrationStatus.NOT_GENERATED; + return getRegistrationStatus() == PersistedInstallation.RegistrationStatus.NOT_GENERATED; } @NonNull public abstract Builder toBuilder(); - /** Returns a default Builder object to create an PersistedFidEntry object */ + /** Returns a default Builder object to create an PersistedInstallationEntry object */ @NonNull - public static PersistedFidEntry.Builder builder() { - return new AutoValue_PersistedFidEntry.Builder() + public static PersistedInstallationEntry.Builder builder() { + return new AutoValue_PersistedInstallationEntry.Builder() .setTokenCreationEpochInSecs(0) - .setRegistrationStatus(PersistedFid.RegistrationStatus.NOT_GENERATED) + .setRegistrationStatus(PersistedInstallation.RegistrationStatus.NOT_GENERATED) .setExpiresInSecs(0); } @@ -75,7 +75,8 @@ public abstract static class Builder { public abstract Builder setFirebaseInstallationId(@NonNull String value); @NonNull - public abstract Builder setRegistrationStatus(@NonNull PersistedFid.RegistrationStatus value); + public abstract Builder setRegistrationStatus( + @NonNull PersistedInstallation.RegistrationStatus value); @NonNull public abstract Builder setAuthToken(@Nullable String value); @@ -90,6 +91,6 @@ public abstract static class Builder { public abstract Builder setTokenCreationEpochInSecs(long value); @NonNull - public abstract PersistedFidEntry build(); + public abstract PersistedInstallationEntry build(); } }