Skip to content

Commit d4776b3

Browse files
authored
Migrate RC to depend directly on Installations SDK. (#1579)
1 parent b2e6da4 commit d4776b3

File tree

17 files changed

+182
-169
lines changed

17 files changed

+182
-169
lines changed

firebase-config/bandwagoner/bandwagoner.gradle

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,8 @@ dependencies {
6666
implementation project(":firebase-common")
6767
implementation project(":firebase-components")
6868

69-
implementation('com.google.firebase:firebase-iid:20.1.5') {
70-
exclude group: 'com.google.firebase', module: 'firebase-common'
71-
exclude group: 'com.google.firebase', module: 'firebase-components'
72-
}
69+
implementation project(":firebase-installations-interop")
70+
runtimeOnly project(":firebase-installations")
7371

7472
implementation 'com.google.android.gms:play-services-basement:17.0.0'
7573
implementation 'com.google.android.gms:play-services-tasks:17.0.0'

firebase-config/bandwagoner/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
android:versionName="3.0.0">
2323

2424

25-
<!--Needed for Firebase IID's getToken method.-->
25+
<!--Needed for Firebase Installations getToken method.-->
2626
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
2727
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
2828

@@ -43,7 +43,7 @@
4343

4444
<service android:exported="false" android:name="com.google.firebase.components.ComponentDiscoveryService">
4545
<meta-data
46-
android:name="com.google.firebase.components:com.google.firebase.iid.Registrar"
46+
android:name="com.google.firebase.components:com.google.firebase.installations.FirebaseInstallationsRegistrar"
4747
android:value="com.google.firebase.components.ComponentRegistrar"/>
4848
</service>
4949

firebase-config/bandwagoner/src/main/java/com/googletest/firebase/remoteconfig/bandwagoner/ApiFragment.java

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@
3333
import androidx.annotation.IdRes;
3434
import androidx.fragment.app.Fragment;
3535
import com.google.android.gms.tasks.Task;
36-
import com.google.firebase.iid.FirebaseInstanceId;
36+
import com.google.android.gms.tasks.Tasks;
37+
import com.google.firebase.FirebaseApp;
38+
import com.google.firebase.installations.FirebaseInstallationsApi;
39+
import com.google.firebase.installations.InstallationTokenResult;
3740
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
3841
import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings;
3942

@@ -46,20 +49,25 @@
4649
public class ApiFragment extends Fragment {
4750

4851
private FirebaseRemoteConfig frc;
52+
private FirebaseInstallationsApi firebaseInstallations;
4953
private View rootView;
5054
private EditText minimumFetchIntervalText;
5155
private EditText parameterKeyText;
5256
private TextView parameterValueText;
5357
private TextView apiCallProgressText;
5458
private TextView apiCallResultsText;
5559

60+
private static final String TAG = "Bandwagoner";
61+
5662
@Override
5763
public void onCreate(Bundle savedInstanceState) {
5864
super.onCreate(savedInstanceState);
5965

6066
frc = FirebaseRemoteConfig.getInstance();
6167
frc.setConfigSettings(
6268
new FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(true).build());
69+
70+
firebaseInstallations = FirebaseApp.getInstance().get(FirebaseInstallationsApi.class);
6371
}
6472

6573
@Override
@@ -87,9 +95,29 @@ public View onCreateView(
8795
TextView sdkVersionText = rootView.findViewById(R.id.sdk_version_text);
8896

8997
TextView iidText = rootView.findViewById(R.id.iid_text);
90-
iidText.setText("IID: " + FirebaseInstanceId.getInstance().getId());
9198

92-
apiCallResultsText.setText(FirebaseInstanceId.getInstance().getToken());
99+
Task<String> installationIdTask = firebaseInstallations.getId();
100+
Task<InstallationTokenResult> installationAuthTokenTask = firebaseInstallations.getToken(false);
101+
102+
Tasks.whenAllComplete(installationIdTask, installationAuthTokenTask)
103+
.addOnCompleteListener(
104+
unusedCompletedTasks -> {
105+
if (installationIdTask.isSuccessful()) {
106+
iidText.setText(
107+
String.format("Installation ID: %s", installationIdTask.getResult()));
108+
} else {
109+
Log.e(TAG, "Error getting installation ID", installationIdTask.getException());
110+
}
111+
112+
if (installationAuthTokenTask.isSuccessful()) {
113+
apiCallResultsText.setText(installationAuthTokenTask.getResult().getToken());
114+
} else {
115+
Log.e(
116+
TAG,
117+
"Error getting installation authentication token",
118+
installationAuthTokenTask.getException());
119+
}
120+
});
93121

94122
return rootView;
95123
}

firebase-config/firebase-config.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ dependencies {
8585
implementation project(':firebase-common')
8686
implementation project(':firebase-abt')
8787
implementation project(':firebase-components')
88-
implementation('com.google.firebase:firebase-iid:20.1.5') {
89-
exclude group: 'com.google.firebase', module: 'firebase-common'
90-
exclude group: 'com.google.firebase', module: 'firebase-components'
91-
}
88+
implementation project(':firebase-installations-interop')
89+
runtimeOnly project(':firebase-installations')
90+
9291
implementation 'com.google.firebase:firebase-measurement-connector:18.0.0'
9392
implementation 'com.google.protobuf:protobuf-lite:3.0.1'
93+
implementation 'com.google.android.gms:play-services-tasks:17.0.2'
9494

9595
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'
9696

firebase-config/ktx/ktx.gradle

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ dependencies {
4949
implementation project(':firebase-common:ktx')
5050
implementation project(':firebase-config')
5151
implementation project(':firebase-abt')
52-
implementation ('com.google.firebase:firebase-iid:20.1.5') {
53-
exclude group: 'com.google.firebase', module: 'firebase-common'
54-
exclude group: 'com.google.firebase', module: 'firebase-components'
55-
}
52+
implementation project(':firebase-installations-interop')
53+
runtimeOnly project(':firebase-installations')
54+
5655
implementation 'androidx.annotation:annotation:1.1.0'
5756

5857
testImplementation "org.robolectric:robolectric:$robolectricVersion"

firebase-config/ktx/src/test/kotlin/com/google/firebase/remoteconfig/TestConstructorUtil.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ import com.google.firebase.remoteconfig.internal.ConfigGetParameterHandler
2222
import com.google.firebase.remoteconfig.internal.ConfigMetadataClient
2323
import java.util.concurrent.Executor
2424
import com.google.firebase.abt.FirebaseABTesting
25-
import com.google.firebase.iid.FirebaseInstanceId
25+
import com.google.firebase.installations.FirebaseInstallationsApi
2626

2727
// This method is a workaround for testing. It enable us to create a FirebaseRemoteConfig object
2828
// with mocks using the package-private constructor.
2929
fun createRemoteConfig(
3030
context: Context?,
3131
firebaseApp: FirebaseApp,
32-
firebaseInstanceId: FirebaseInstanceId,
32+
firebaseInstallations: FirebaseInstallationsApi,
3333
firebaseAbt: FirebaseABTesting?,
3434
executor: Executor,
3535
fetchedConfigsCache: ConfigCacheClient,
@@ -42,7 +42,7 @@ fun createRemoteConfig(
4242
return FirebaseRemoteConfig(
4343
context,
4444
firebaseApp,
45-
firebaseInstanceId,
45+
firebaseInstallations,
4646
firebaseAbt,
4747
executor,
4848
fetchedConfigsCache,

firebase-config/ktx/src/test/kotlin/com/google/firebase/remoteconfig/ktx/RemoteConfigTests.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import com.google.firebase.remoteconfig.internal.ConfigFetchHandler
2727
import com.google.firebase.remoteconfig.internal.ConfigGetParameterHandler
2828
import com.google.firebase.remoteconfig.internal.ConfigMetadataClient
2929
import com.google.common.util.concurrent.MoreExecutors
30-
import com.google.firebase.iid.FirebaseInstanceId
30+
import com.google.firebase.installations.FirebaseInstallationsApi
3131
import com.google.firebase.ktx.app
3232
import com.google.firebase.ktx.initialize
3333
import org.junit.After
@@ -129,7 +129,7 @@ class ConfigTests : BaseTestCase() {
129129
val remoteConfig = createRemoteConfig(
130130
context = null,
131131
firebaseApp = Firebase.app(EXISTING_APP),
132-
firebaseInstanceId = mock(FirebaseInstanceId::class.java),
132+
firebaseInstallations = mock(FirebaseInstallationsApi::class.java),
133133
firebaseAbt = null,
134134
executor = directExecutor,
135135
fetchedConfigsCache = mock(ConfigCacheClient::class.java),

firebase-config/src/androidTest/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigIntegrationTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import com.google.firebase.FirebaseApp;
3131
import com.google.firebase.FirebaseOptions;
3232
import com.google.firebase.abt.FirebaseABTesting;
33-
import com.google.firebase.iid.FirebaseInstanceId;
33+
import com.google.firebase.installations.FirebaseInstallationsApi;
3434
import com.google.firebase.remoteconfig.internal.ConfigCacheClient;
3535
import com.google.firebase.remoteconfig.internal.ConfigContainer;
3636
import com.google.firebase.remoteconfig.internal.ConfigFetchHandler;
@@ -64,7 +64,7 @@ public class FirebaseRemoteConfigIntegrationTest {
6464
@Mock private ConfigCacheClient mockFireperfActivatedCache;
6565

6666
@Mock private FirebaseABTesting mockFirebaseAbt;
67-
@Mock private FirebaseInstanceId mockFirebaseInstanceId;
67+
@Mock private FirebaseInstallationsApi mockFirebaseInstallations;
6868
private FirebaseRemoteConfig frc;
6969

7070
// We use a HashMap so that Mocking is easier.
@@ -96,7 +96,7 @@ public void setUp() {
9696
new FirebaseRemoteConfig(
9797
context,
9898
firebaseApp,
99-
mockFirebaseInstanceId,
99+
mockFirebaseInstallations,
100100
mockFirebaseAbt,
101101
directExecutor,
102102
mockFetchedCache,

firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfig.java

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import com.google.firebase.FirebaseApp;
2727
import com.google.firebase.abt.AbtException;
2828
import com.google.firebase.abt.FirebaseABTesting;
29-
import com.google.firebase.iid.FirebaseInstanceId;
30-
import com.google.firebase.iid.InstanceIdResult;
29+
import com.google.firebase.installations.FirebaseInstallationsApi;
30+
import com.google.firebase.installations.InstallationTokenResult;
3131
import com.google.firebase.remoteconfig.internal.ConfigCacheClient;
3232
import com.google.firebase.remoteconfig.internal.ConfigContainer;
3333
import com.google.firebase.remoteconfig.internal.ConfigFetchHandler;
@@ -66,10 +66,12 @@ public class FirebaseRemoteConfig {
6666
* <p>{@link FirebaseRemoteConfig} uses the default {@link FirebaseApp}, so if no {@link
6767
* FirebaseApp} has been initialized yet, this method throws an {@link IllegalStateException}.
6868
*
69-
* <p>To identify the current app instance, the fetch request creates a Firebase Instance ID
70-
* token, which periodically sends data to the Firebase backend. To stop the periodic sync, call
71-
* {@link com.google.firebase.iid.FirebaseInstanceId#deleteInstanceId}. To create a new token and
72-
* resume the periodic sync, call {@code fetchConfig} again.
69+
* <p>Note: Also initializes the Firebase installations SDK that creates installation IDs to
70+
* identify Firebase installations and periodically sends data to Firebase servers. Remote Config
71+
* requires installation IDs for Fetch requests. To stop the periodic sync, call {@link
72+
* com.google.firebase.installations.FirebaseInstallations#delete}. Sending a Fetch request after
73+
* deletion will create a new installation ID for this Firebase installation and resume the
74+
* periodic sync.
7375
*
7476
* @return A singleton instance of {@link FirebaseRemoteConfig} for the default {@link
7577
* FirebaseApp}.
@@ -149,7 +151,7 @@ public static FirebaseRemoteConfig getInstance(@NonNull FirebaseApp app) {
149151
private final ConfigFetchHandler fetchHandler;
150152
private final ConfigGetParameterHandler getHandler;
151153
private final ConfigMetadataClient frcMetadata;
152-
private final FirebaseInstanceId firebaseInstanceId;
154+
private final FirebaseInstallationsApi firebaseInstallations;
153155

154156
/**
155157
* Firebase Remote Config constructor.
@@ -159,7 +161,7 @@ public static FirebaseRemoteConfig getInstance(@NonNull FirebaseApp app) {
159161
FirebaseRemoteConfig(
160162
Context context,
161163
FirebaseApp firebaseApp,
162-
FirebaseInstanceId firebaseInstanceId,
164+
FirebaseInstallationsApi firebaseInstallations,
163165
@Nullable FirebaseABTesting firebaseAbt,
164166
Executor executor,
165167
ConfigCacheClient fetchedConfigsCache,
@@ -170,7 +172,7 @@ public static FirebaseRemoteConfig getInstance(@NonNull FirebaseApp app) {
170172
ConfigMetadataClient frcMetadata) {
171173
this.context = context;
172174
this.firebaseApp = firebaseApp;
173-
this.firebaseInstanceId = firebaseInstanceId;
175+
this.firebaseInstallations = firebaseInstallations;
174176
this.firebaseAbt = firebaseAbt;
175177
this.executor = executor;
176178
this.fetchedConfigsCache = fetchedConfigsCache;
@@ -191,14 +193,16 @@ public Task<FirebaseRemoteConfigInfo> ensureInitialized() {
191193
Task<ConfigContainer> defaultsConfigsTask = defaultConfigsCache.get();
192194
Task<ConfigContainer> fetchedConfigsTask = fetchedConfigsCache.get();
193195
Task<FirebaseRemoteConfigInfo> metadataTask = Tasks.call(executor, this::getInfo);
194-
Task<InstanceIdResult> instanceIdTask = firebaseInstanceId.getInstanceId();
196+
Task<String> installationIdTask = firebaseInstallations.getId();
197+
Task<InstallationTokenResult> installationTokenTask = firebaseInstallations.getToken(false);
195198

196199
return Tasks.whenAllComplete(
197200
activatedConfigsTask,
198201
defaultsConfigsTask,
199202
fetchedConfigsTask,
200203
metadataTask,
201-
instanceIdTask)
204+
installationIdTask,
205+
installationTokenTask)
202206
.continueWith(executor, (unusedListOfCompletedTasks) -> metadataTask.getResult());
203207
}
204208

@@ -301,10 +305,12 @@ public Task<Boolean> activate() {
301305
* FirebaseRemoteConfigSettings.Builder#setMinimumFetchIntervalInSeconds(long)}; the static
302306
* default is 12 hours.
303307
*
304-
* <p>To identify the current app instance, the fetch request creates a Firebase Instance ID
305-
* token, which periodically sends data to the Firebase backend. To stop the periodic sync, call
306-
* {@link com.google.firebase.iid.FirebaseInstanceId#deleteInstanceId}. To create a new token and
307-
* resume the periodic sync, call {@code fetchConfig} again.
308+
* <p>Note: Also initializes the Firebase installations SDK that creates installation IDs to
309+
* identify Firebase installations and periodically sends data to Firebase servers. Remote Config
310+
* requires installation IDs for Fetch requests. To stop the periodic sync, call {@link
311+
* com.google.firebase.installations.FirebaseInstallations#delete}. Sending a Fetch request after
312+
* deletion will create a new installation ID for this Firebase installation and resume the
313+
* periodic sync.
308314
*
309315
* @return {@link Task} representing the {@code fetch} call.
310316
*/
@@ -324,10 +330,12 @@ public Task<Void> fetch() {
324330
* <p>Depending on the time elapsed since the last fetch from the Firebase Remote Config backend,
325331
* configs are either served from local storage, or fetched from the backend.
326332
*
327-
* <p>To identify the current app instance, the fetch request creates a Firebase Instance ID
328-
* token, which periodically sends data to the Firebase backend. To stop the periodic sync, call
329-
* {@link com.google.firebase.iid.FirebaseInstanceId#deleteInstanceId}. To create a new token and
330-
* resume the periodic sync, call {@code fetchConfig} again.
333+
* <p>Note: Also initializes the Firebase installations SDK that creates installation IDs to
334+
* identify Firebase installations and periodically sends data to Firebase servers. Remote Config
335+
* requires installation IDs for Fetch requests. To stop the periodic sync, call {@link
336+
* com.google.firebase.installations.FirebaseInstallations#delete}. Sending a Fetch request after
337+
* deletion will create a new installation ID for this Firebase installation and resume the
338+
* periodic sync.
331339
*
332340
* @param minimumFetchIntervalInSeconds If configs in the local storage were fetched more than
333341
* this many seconds ago, configs are served from the backend instead of local storage.

firebase-config/src/main/java/com/google/firebase/remoteconfig/RemoteConfigComponent.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import com.google.firebase.FirebaseApp;
2727
import com.google.firebase.abt.FirebaseABTesting;
2828
import com.google.firebase.analytics.connector.AnalyticsConnector;
29-
import com.google.firebase.iid.FirebaseInstanceId;
29+
import com.google.firebase.installations.FirebaseInstallationsApi;
3030
import com.google.firebase.remoteconfig.internal.ConfigCacheClient;
3131
import com.google.firebase.remoteconfig.internal.ConfigFetchHandler;
3232
import com.google.firebase.remoteconfig.internal.ConfigFetchHttpClient;
@@ -76,7 +76,7 @@ public class RemoteConfigComponent {
7676
private final Context context;
7777
private final ExecutorService executorService;
7878
private final FirebaseApp firebaseApp;
79-
private final FirebaseInstanceId firebaseInstanceId;
79+
private final FirebaseInstallationsApi firebaseInstallations;
8080
private final FirebaseABTesting firebaseAbt;
8181
@Nullable private final AnalyticsConnector analyticsConnector;
8282

@@ -89,14 +89,14 @@ public class RemoteConfigComponent {
8989
RemoteConfigComponent(
9090
Context context,
9191
FirebaseApp firebaseApp,
92-
FirebaseInstanceId firebaseInstanceId,
92+
FirebaseInstallationsApi firebaseInstallations,
9393
FirebaseABTesting firebaseAbt,
9494
@Nullable AnalyticsConnector analyticsConnector) {
9595
this(
9696
context,
9797
Executors.newCachedThreadPool(),
9898
firebaseApp,
99-
firebaseInstanceId,
99+
firebaseInstallations,
100100
firebaseAbt,
101101
analyticsConnector,
102102
new LegacyConfigsHandler(context, firebaseApp.getOptions().getApplicationId()),
@@ -109,15 +109,15 @@ protected RemoteConfigComponent(
109109
Context context,
110110
ExecutorService executorService,
111111
FirebaseApp firebaseApp,
112-
FirebaseInstanceId firebaseInstanceId,
112+
FirebaseInstallationsApi firebaseInstallations,
113113
FirebaseABTesting firebaseAbt,
114114
@Nullable AnalyticsConnector analyticsConnector,
115115
LegacyConfigsHandler legacyConfigsHandler,
116116
boolean loadGetDefault) {
117117
this.context = context;
118118
this.executorService = executorService;
119119
this.firebaseApp = firebaseApp;
120-
this.firebaseInstanceId = firebaseInstanceId;
120+
this.firebaseInstallations = firebaseInstallations;
121121
this.firebaseAbt = firebaseAbt;
122122
this.analyticsConnector = analyticsConnector;
123123

@@ -156,7 +156,7 @@ public synchronized FirebaseRemoteConfig get(String namespace) {
156156
return get(
157157
firebaseApp,
158158
namespace,
159-
firebaseInstanceId,
159+
firebaseInstallations,
160160
firebaseAbt,
161161
executorService,
162162
fetchedCacheClient,
@@ -171,7 +171,7 @@ public synchronized FirebaseRemoteConfig get(String namespace) {
171171
synchronized FirebaseRemoteConfig get(
172172
FirebaseApp firebaseApp,
173173
String namespace,
174-
FirebaseInstanceId firebaseInstanceId,
174+
FirebaseInstallationsApi firebaseInstallations,
175175
FirebaseABTesting firebaseAbt,
176176
Executor executor,
177177
ConfigCacheClient fetchedClient,
@@ -185,7 +185,7 @@ synchronized FirebaseRemoteConfig get(
185185
new FirebaseRemoteConfig(
186186
context,
187187
firebaseApp,
188-
firebaseInstanceId,
188+
firebaseInstallations,
189189
isAbtSupported(firebaseApp, namespace) ? firebaseAbt : null,
190190
executor,
191191
fetchedClient,
@@ -240,7 +240,7 @@ ConfigFetchHttpClient getFrcBackendApiClient(
240240
synchronized ConfigFetchHandler getFetchHandler(
241241
String namespace, ConfigCacheClient fetchedCacheClient, ConfigMetadataClient metadataClient) {
242242
return new ConfigFetchHandler(
243-
firebaseInstanceId,
243+
firebaseInstallations,
244244
isPrimaryApp(firebaseApp) ? analyticsConnector : null,
245245
executorService,
246246
DEFAULT_CLOCK,

0 commit comments

Comments
 (0)