Skip to content

Migrate RC to depend directly on Installations SDK. #1579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions firebase-config/bandwagoner/bandwagoner.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ dependencies {
implementation project(":firebase-common")
implementation project(":firebase-components")

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

implementation 'com.google.android.gms:play-services-basement:17.0.0'
implementation 'com.google.android.gms:play-services-tasks:17.0.0'
Expand Down
4 changes: 2 additions & 2 deletions firebase-config/bandwagoner/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
android:versionName="3.0.0">


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

Expand All @@ -43,7 +43,7 @@

<service android:exported="false" android:name="com.google.firebase.components.ComponentDiscoveryService">
<meta-data
android:name="com.google.firebase.components:com.google.firebase.iid.Registrar"
android:name="com.google.firebase.components:com.google.firebase.installations.FirebaseInstallationsRegistrar"
android:value="com.google.firebase.components.ComponentRegistrar"/>
</service>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@
import androidx.annotation.IdRes;
import androidx.fragment.app.Fragment;
import com.google.android.gms.tasks.Task;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.android.gms.tasks.Tasks;
import com.google.firebase.FirebaseApp;
import com.google.firebase.installations.FirebaseInstallationsApi;
import com.google.firebase.installations.InstallationTokenResult;
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings;

Expand All @@ -46,20 +49,25 @@
public class ApiFragment extends Fragment {

private FirebaseRemoteConfig frc;
private FirebaseInstallationsApi firebaseInstallations;
private View rootView;
private EditText minimumFetchIntervalText;
private EditText parameterKeyText;
private TextView parameterValueText;
private TextView apiCallProgressText;
private TextView apiCallResultsText;

private static final String TAG = "Bandwagoner";

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

frc = FirebaseRemoteConfig.getInstance();
frc.setConfigSettings(
new FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(true).build());

firebaseInstallations = FirebaseApp.getInstance().get(FirebaseInstallationsApi.class);
}

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

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

apiCallResultsText.setText(FirebaseInstanceId.getInstance().getToken());
Task<String> installationIdTask = firebaseInstallations.getId();
Task<InstallationTokenResult> installationAuthTokenTask = firebaseInstallations.getToken(false);

Tasks.whenAllComplete(installationIdTask, installationAuthTokenTask)
.addOnCompleteListener(
unusedCompletedTasks -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about ignoredTasks?
I am not sure what Android naming convention is here, but do you also use the underscore "_" prefix?
_ignoredTasks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure there's a real convention in Android or Java, but we use "unused" consistently as a prefix in Remote Config at least, so I'd lean towards keeping it.

if (installationIdTask.isSuccessful()) {
iidText.setText(
String.format("Installation ID: %s", installationIdTask.getResult()));
} else {
Log.e(TAG, "Error getting installation ID", installationIdTask.getException());
}

if (installationAuthTokenTask.isSuccessful()) {
apiCallResultsText.setText(installationAuthTokenTask.getResult().getToken());
} else {
Log.e(
TAG,
"Error getting installation authentication token",
installationAuthTokenTask.getException());
}
});

return rootView;
}
Expand Down
8 changes: 4 additions & 4 deletions firebase-config/firebase-config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ dependencies {
implementation project(':firebase-common')
implementation project(':firebase-abt')
implementation project(':firebase-components')
implementation('com.google.firebase:firebase-iid:20.1.5') {
exclude group: 'com.google.firebase', module: 'firebase-common'
exclude group: 'com.google.firebase', module: 'firebase-components'
}
implementation project(':firebase-installations-interop')
runtimeOnly project(':firebase-installations')

implementation 'com.google.firebase:firebase-measurement-connector:18.0.0'
implementation 'com.google.protobuf:protobuf-lite:3.0.1'
implementation 'com.google.android.gms:play-services-tasks:17.0.2'

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

Expand Down
7 changes: 3 additions & 4 deletions firebase-config/ktx/ktx.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ dependencies {
implementation project(':firebase-common:ktx')
implementation project(':firebase-config')
implementation project(':firebase-abt')
implementation ('com.google.firebase:firebase-iid:20.1.5') {
exclude group: 'com.google.firebase', module: 'firebase-common'
exclude group: 'com.google.firebase', module: 'firebase-components'
}
implementation project(':firebase-installations-interop')
runtimeOnly project(':firebase-installations')

implementation 'androidx.annotation:annotation:1.1.0'

testImplementation "org.robolectric:robolectric:$robolectricVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import com.google.firebase.remoteconfig.internal.ConfigGetParameterHandler
import com.google.firebase.remoteconfig.internal.ConfigMetadataClient
import java.util.concurrent.Executor
import com.google.firebase.abt.FirebaseABTesting
import com.google.firebase.iid.FirebaseInstanceId
import com.google.firebase.installations.FirebaseInstallationsApi

// This method is a workaround for testing. It enable us to create a FirebaseRemoteConfig object
// with mocks using the package-private constructor.
fun createRemoteConfig(
context: Context?,
firebaseApp: FirebaseApp,
firebaseInstanceId: FirebaseInstanceId,
firebaseInstallations: FirebaseInstallationsApi,
firebaseAbt: FirebaseABTesting?,
executor: Executor,
fetchedConfigsCache: ConfigCacheClient,
Expand All @@ -42,7 +42,7 @@ fun createRemoteConfig(
return FirebaseRemoteConfig(
context,
firebaseApp,
firebaseInstanceId,
firebaseInstallations,
firebaseAbt,
executor,
fetchedConfigsCache,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.google.firebase.remoteconfig.internal.ConfigFetchHandler
import com.google.firebase.remoteconfig.internal.ConfigGetParameterHandler
import com.google.firebase.remoteconfig.internal.ConfigMetadataClient
import com.google.common.util.concurrent.MoreExecutors
import com.google.firebase.iid.FirebaseInstanceId
import com.google.firebase.installations.FirebaseInstallationsApi
import com.google.firebase.ktx.app
import com.google.firebase.ktx.initialize
import org.junit.After
Expand Down Expand Up @@ -129,7 +129,7 @@ class ConfigTests : BaseTestCase() {
val remoteConfig = createRemoteConfig(
context = null,
firebaseApp = Firebase.app(EXISTING_APP),
firebaseInstanceId = mock(FirebaseInstanceId::class.java),
firebaseInstallations = mock(FirebaseInstallationsApi::class.java),
firebaseAbt = null,
executor = directExecutor,
fetchedConfigsCache = mock(ConfigCacheClient::class.java),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.abt.FirebaseABTesting;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.installations.FirebaseInstallationsApi;
import com.google.firebase.remoteconfig.internal.ConfigCacheClient;
import com.google.firebase.remoteconfig.internal.ConfigContainer;
import com.google.firebase.remoteconfig.internal.ConfigFetchHandler;
Expand Down Expand Up @@ -64,7 +64,7 @@ public class FirebaseRemoteConfigIntegrationTest {
@Mock private ConfigCacheClient mockFireperfActivatedCache;

@Mock private FirebaseABTesting mockFirebaseAbt;
@Mock private FirebaseInstanceId mockFirebaseInstanceId;
@Mock private FirebaseInstallationsApi mockFirebaseInstallations;
private FirebaseRemoteConfig frc;

// We use a HashMap so that Mocking is easier.
Expand Down Expand Up @@ -96,7 +96,7 @@ public void setUp() {
new FirebaseRemoteConfig(
context,
firebaseApp,
mockFirebaseInstanceId,
mockFirebaseInstallations,
mockFirebaseAbt,
directExecutor,
mockFetchedCache,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import com.google.firebase.FirebaseApp;
import com.google.firebase.abt.AbtException;
import com.google.firebase.abt.FirebaseABTesting;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.InstanceIdResult;
import com.google.firebase.installations.FirebaseInstallationsApi;
import com.google.firebase.installations.InstallationTokenResult;
import com.google.firebase.remoteconfig.internal.ConfigCacheClient;
import com.google.firebase.remoteconfig.internal.ConfigContainer;
import com.google.firebase.remoteconfig.internal.ConfigFetchHandler;
Expand Down Expand Up @@ -66,10 +66,12 @@ public class FirebaseRemoteConfig {
* <p>{@link FirebaseRemoteConfig} uses the default {@link FirebaseApp}, so if no {@link
* FirebaseApp} has been initialized yet, this method throws an {@link IllegalStateException}.
*
* <p>To identify the current app instance, the fetch request creates a Firebase Instance ID
* token, which periodically sends data to the Firebase backend. To stop the periodic sync, call
* {@link com.google.firebase.iid.FirebaseInstanceId#deleteInstanceId}. To create a new token and
* resume the periodic sync, call {@code fetchConfig} again.
* <p>Note: Also initializes the Firebase installations SDK that creates installation IDs to
* identify Firebase installations and periodically sends data to Firebase servers. Remote Config
* requires installation IDs for Fetch requests. To stop the periodic sync, call {@link
* com.google.firebase.installations.FirebaseInstallations#delete}. Sending a Fetch request after
* deletion will create a new installation ID for this Firebase installation and resume the
* periodic sync.
*
* @return A singleton instance of {@link FirebaseRemoteConfig} for the default {@link
* FirebaseApp}.
Expand Down Expand Up @@ -149,7 +151,7 @@ public static FirebaseRemoteConfig getInstance(@NonNull FirebaseApp app) {
private final ConfigFetchHandler fetchHandler;
private final ConfigGetParameterHandler getHandler;
private final ConfigMetadataClient frcMetadata;
private final FirebaseInstanceId firebaseInstanceId;
private final FirebaseInstallationsApi firebaseInstallations;

/**
* Firebase Remote Config constructor.
Expand All @@ -159,7 +161,7 @@ public static FirebaseRemoteConfig getInstance(@NonNull FirebaseApp app) {
FirebaseRemoteConfig(
Context context,
FirebaseApp firebaseApp,
FirebaseInstanceId firebaseInstanceId,
FirebaseInstallationsApi firebaseInstallations,
@Nullable FirebaseABTesting firebaseAbt,
Executor executor,
ConfigCacheClient fetchedConfigsCache,
Expand All @@ -170,7 +172,7 @@ public static FirebaseRemoteConfig getInstance(@NonNull FirebaseApp app) {
ConfigMetadataClient frcMetadata) {
this.context = context;
this.firebaseApp = firebaseApp;
this.firebaseInstanceId = firebaseInstanceId;
this.firebaseInstallations = firebaseInstallations;
this.firebaseAbt = firebaseAbt;
this.executor = executor;
this.fetchedConfigsCache = fetchedConfigsCache;
Expand All @@ -191,14 +193,16 @@ public Task<FirebaseRemoteConfigInfo> ensureInitialized() {
Task<ConfigContainer> defaultsConfigsTask = defaultConfigsCache.get();
Task<ConfigContainer> fetchedConfigsTask = fetchedConfigsCache.get();
Task<FirebaseRemoteConfigInfo> metadataTask = Tasks.call(executor, this::getInfo);
Task<InstanceIdResult> instanceIdTask = firebaseInstanceId.getInstanceId();
Task<String> installationIdTask = firebaseInstallations.getId();
Task<InstallationTokenResult> installationTokenTask = firebaseInstallations.getToken(false);

return Tasks.whenAllComplete(
activatedConfigsTask,
defaultsConfigsTask,
fetchedConfigsTask,
metadataTask,
instanceIdTask)
installationIdTask,
installationTokenTask)
.continueWith(executor, (unusedListOfCompletedTasks) -> metadataTask.getResult());
}

Expand Down Expand Up @@ -301,10 +305,12 @@ public Task<Boolean> activate() {
* FirebaseRemoteConfigSettings.Builder#setMinimumFetchIntervalInSeconds(long)}; the static
* default is 12 hours.
*
* <p>To identify the current app instance, the fetch request creates a Firebase Instance ID
* token, which periodically sends data to the Firebase backend. To stop the periodic sync, call
* {@link com.google.firebase.iid.FirebaseInstanceId#deleteInstanceId}. To create a new token and
* resume the periodic sync, call {@code fetchConfig} again.
* <p>Note: Also initializes the Firebase installations SDK that creates installation IDs to
* identify Firebase installations and periodically sends data to Firebase servers. Remote Config
* requires installation IDs for Fetch requests. To stop the periodic sync, call {@link
* com.google.firebase.installations.FirebaseInstallations#delete}. Sending a Fetch request after
* deletion will create a new installation ID for this Firebase installation and resume the
* periodic sync.
*
* @return {@link Task} representing the {@code fetch} call.
*/
Expand All @@ -324,10 +330,12 @@ public Task<Void> fetch() {
* <p>Depending on the time elapsed since the last fetch from the Firebase Remote Config backend,
* configs are either served from local storage, or fetched from the backend.
*
* <p>To identify the current app instance, the fetch request creates a Firebase Instance ID
* token, which periodically sends data to the Firebase backend. To stop the periodic sync, call
* {@link com.google.firebase.iid.FirebaseInstanceId#deleteInstanceId}. To create a new token and
* resume the periodic sync, call {@code fetchConfig} again.
* <p>Note: Also initializes the Firebase installations SDK that creates installation IDs to
* identify Firebase installations and periodically sends data to Firebase servers. Remote Config
* requires installation IDs for Fetch requests. To stop the periodic sync, call {@link
* com.google.firebase.installations.FirebaseInstallations#delete}. Sending a Fetch request after
* deletion will create a new installation ID for this Firebase installation and resume the
* periodic sync.
*
* @param minimumFetchIntervalInSeconds If configs in the local storage were fetched more than
* this many seconds ago, configs are served from the backend instead of local storage.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.google.firebase.FirebaseApp;
import com.google.firebase.abt.FirebaseABTesting;
import com.google.firebase.analytics.connector.AnalyticsConnector;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.installations.FirebaseInstallationsApi;
import com.google.firebase.remoteconfig.internal.ConfigCacheClient;
import com.google.firebase.remoteconfig.internal.ConfigFetchHandler;
import com.google.firebase.remoteconfig.internal.ConfigFetchHttpClient;
Expand Down Expand Up @@ -76,7 +76,7 @@ public class RemoteConfigComponent {
private final Context context;
private final ExecutorService executorService;
private final FirebaseApp firebaseApp;
private final FirebaseInstanceId firebaseInstanceId;
private final FirebaseInstallationsApi firebaseInstallations;
private final FirebaseABTesting firebaseAbt;
@Nullable private final AnalyticsConnector analyticsConnector;

Expand All @@ -89,14 +89,14 @@ public class RemoteConfigComponent {
RemoteConfigComponent(
Context context,
FirebaseApp firebaseApp,
FirebaseInstanceId firebaseInstanceId,
FirebaseInstallationsApi firebaseInstallations,
FirebaseABTesting firebaseAbt,
@Nullable AnalyticsConnector analyticsConnector) {
this(
context,
Executors.newCachedThreadPool(),
firebaseApp,
firebaseInstanceId,
firebaseInstallations,
firebaseAbt,
analyticsConnector,
new LegacyConfigsHandler(context, firebaseApp.getOptions().getApplicationId()),
Expand All @@ -109,15 +109,15 @@ protected RemoteConfigComponent(
Context context,
ExecutorService executorService,
FirebaseApp firebaseApp,
FirebaseInstanceId firebaseInstanceId,
FirebaseInstallationsApi firebaseInstallations,
FirebaseABTesting firebaseAbt,
@Nullable AnalyticsConnector analyticsConnector,
LegacyConfigsHandler legacyConfigsHandler,
boolean loadGetDefault) {
this.context = context;
this.executorService = executorService;
this.firebaseApp = firebaseApp;
this.firebaseInstanceId = firebaseInstanceId;
this.firebaseInstallations = firebaseInstallations;
this.firebaseAbt = firebaseAbt;
this.analyticsConnector = analyticsConnector;

Expand Down Expand Up @@ -156,7 +156,7 @@ public synchronized FirebaseRemoteConfig get(String namespace) {
return get(
firebaseApp,
namespace,
firebaseInstanceId,
firebaseInstallations,
firebaseAbt,
executorService,
fetchedCacheClient,
Expand All @@ -171,7 +171,7 @@ public synchronized FirebaseRemoteConfig get(String namespace) {
synchronized FirebaseRemoteConfig get(
FirebaseApp firebaseApp,
String namespace,
FirebaseInstanceId firebaseInstanceId,
FirebaseInstallationsApi firebaseInstallations,
FirebaseABTesting firebaseAbt,
Executor executor,
ConfigCacheClient fetchedClient,
Expand All @@ -185,7 +185,7 @@ synchronized FirebaseRemoteConfig get(
new FirebaseRemoteConfig(
context,
firebaseApp,
firebaseInstanceId,
firebaseInstallations,
isAbtSupported(firebaseApp, namespace) ? firebaseAbt : null,
executor,
fetchedClient,
Expand Down Expand Up @@ -240,7 +240,7 @@ ConfigFetchHttpClient getFrcBackendApiClient(
synchronized ConfigFetchHandler getFetchHandler(
String namespace, ConfigCacheClient fetchedCacheClient, ConfigMetadataClient metadataClient) {
return new ConfigFetchHandler(
firebaseInstanceId,
firebaseInstallations,
isPrimaryApp(firebaseApp) ? analyticsConnector : null,
executorService,
DEFAULT_CLOCK,
Expand Down
Loading