Skip to content

[Firebase Segmentation] Add custom installation id cache layer and tests for it. #524

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 20 commits into from
Jun 18, 2019

Conversation

diwu-arete
Copy link
Contributor

No description provided.

schmidt-sebastian and others added 6 commits June 13, 2019 08:46
* fix functions

* update minsdk version

* remove idea
* Set test type to release only in CI.

This fixes Android Studio issue, where it is impossible to run
integration tests in debug mode.

Additionally move build type configuration to FirebaseLibraryPlugin to
avoid projects.all configuration in gradle.

* Add comment back.
@googlebot googlebot added the cla: yes Override cla label Jun 14, 2019
@diwu-arete diwu-arete requested a review from vkryachko June 15, 2019 00:05
@diwu-arete diwu-arete self-assigned this Jun 15, 2019
Copy link
Member

@vkryachko vkryachko left a comment

Choose a reason for hiding this comment

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

Actually, taking a step back: it looks like your persistence needs are pretty simple at the moment: e.g. it's one value per firebase App. That said, do you actually need sqlite? alternatively can you just use shared preferences for persistence?

Related: do you ever plan to support direct boot mode? in which case you might want to persist state in a direct-boot aware way.

rsgowman and others added 3 commits June 17, 2019 16:30
* Minor fix to error message to match the admin sdk.

In particular, it *is* allowed to have slashes, etc in field paths.
This change allows the smoke tests to clean all build variants created
by the infrastructure.
* Update deps to post-androidx gms versions.

Additionally configure sources.jar for SDKs.

* Update functions-ktx deps

* Fix versions.

* unbump fiam version in fiamui-app
@diwu-arete
Copy link
Contributor Author

Actually, taking a step back: it looks like your persistence needs are pretty simple at the moment: e.g. it's one value per firebase App. That said, do you actually need sqlite? alternatively can you just use shared preferences for persistence?

Related: do you ever plan to support direct boot mode? in which case you might want to persist state in a direct-boot aware way.

As talked with Vlad offline, change to use shared preference.

@diwu-arete diwu-arete requested a review from vkryachko June 17, 2019 21:21
private static CustomInstallationIdCache singleton = null;
private final SharedPreferences prefs;

static CustomInstallationIdCache getInstance() {
Copy link
Member

Choose a reason for hiding this comment

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

Due to the way SharedPrefs are implemented, this class does not have to be a singleton, as multiple instances of sharedPrefs that point to the same file share the same thread-safe in-memory backing structure. As a side-effect of doing it your interface will become much simpler, as you won't have to pass FirebaseApp around to be able to read/write to the cache, e.g. something along these lines:

class Cache {
  // note: injecting direct deps only https://github.com/google/guice/wiki/InjectOnlyDirectDependencies
  Cache(String persistenceKey, SharedPreferences prefs) {}
  Value read();
  void write(Value value);
}

When your SDK initializes it can then construct this cache as new Cache(app.getPersistenceKey(), context.getSharedPreferences()); Note that Cache is completely decoupled from FirebaseApp, so there is not need to initialize FirebaseApp during tests, which leads to faster more isolated tests. wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. For passing in a String argument and SharedPreference argument from the caller, I don't like the idea, because I don't want the caller to pass in a random string or a random shared pref name.

  2. For singleton or non-singleton, I don't have a strong opinion. But the singleton mode can centralize management of all FirebaseApps in one shared pref file, which allows to clearAll() for example, and it doesn't hurt the test too much.

Copy link
Member

Choose a reason for hiding this comment

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

I don't feel strongly re 1.

  1. you can centralize all FirebaseApps in one shared pref file even if you don't use a singleton, as calling getSharedPreferences() with the same name+mode returns the same instance, clearAll can also be implemented as a static method that takes a Context. It's ultimately up to your team to decide the best approach here, but I feel like singleton does not provide many benefits due to the nature of how sharedPrefs work. If you do decide to use a singleton, pls make getInstance() thread-safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing to thread-safe singleton.

If we find singleton pattern doesn't work well later, we can always change it.

@diwu-arete diwu-arete requested a review from vkryachko June 18, 2019 17:42
private static CustomInstallationIdCache singleton = null;
private final SharedPreferences prefs;

static CustomInstallationIdCache getInstance() {
Copy link
Member

Choose a reason for hiding this comment

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

I don't feel strongly re 1.

  1. you can centralize all FirebaseApps in one shared pref file even if you don't use a singleton, as calling getSharedPreferences() with the same name+mode returns the same instance, clearAll can also be implemented as a static method that takes a Context. It's ultimately up to your team to decide the best approach here, but I feel like singleton does not provide many benefits due to the nature of how sharedPrefs work. If you do decide to use a singleton, pls make getInstance() thread-safe.

@diwu-arete diwu-arete requested a review from vkryachko June 18, 2019 18:03
vkryachko and others added 2 commits June 18, 2019 14:15
Additionally fix pom filter to exclude multidex from deps.
Copy link
Member

@vkryachko vkryachko left a comment

Choose a reason for hiding this comment

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

Lgmt

@diwu-arete diwu-arete merged commit dc46eee into floc-master Jun 18, 2019
@diwu-arete diwu-arete deleted the arete-floc branch June 18, 2019 21:03
@firebase firebase locked and limited conversation to collaborators Oct 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants