-
Notifications
You must be signed in to change notification settings - Fork 615
[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
Conversation
This effort replaces #494.
* 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.
...e-segmentation/src/main/java/com/google/firebase/segmentation/CustomInstallationIdCache.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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.
...e-segmentation/src/main/java/com/google/firebase/segmentation/CustomInstallationIdCache.java
Show resolved
Hide resolved
...e-segmentation/src/main/java/com/google/firebase/segmentation/CustomInstallationIdCache.java
Outdated
Show resolved
Hide resolved
* 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
As talked with Vlad offline, change to use shared preference. |
private static CustomInstallationIdCache singleton = null; | ||
private final SharedPreferences prefs; | ||
|
||
static CustomInstallationIdCache getInstance() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
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.
-
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.
There was a problem hiding this comment.
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.
- 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 aContext
. 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 makegetInstance()
thread-safe.
There was a problem hiding this comment.
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.
...e-segmentation/src/main/java/com/google/firebase/segmentation/CustomInstallationIdCache.java
Outdated
Show resolved
Hide resolved
...e-segmentation/src/main/java/com/google/firebase/segmentation/CustomInstallationIdCache.java
Show resolved
Hide resolved
...e-segmentation/src/main/java/com/google/firebase/segmentation/CustomInstallationIdCache.java
Outdated
Show resolved
Hide resolved
private static CustomInstallationIdCache singleton = null; | ||
private final SharedPreferences prefs; | ||
|
||
static CustomInstallationIdCache getInstance() { |
There was a problem hiding this comment.
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.
- 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 aContext
. 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 makegetInstance()
thread-safe.
...e-segmentation/src/main/java/com/google/firebase/segmentation/CustomInstallationIdCache.java
Outdated
Show resolved
Hide resolved
Additionally fix pom filter to exclude multidex from deps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgmt
No description provided.