-
Notifications
You must be signed in to change notification settings - Fork 31
STITCH-2510 Java SDK: Alter AuthListener to better represent User lifecycle #97
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
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
e509edd
Java SDK: Alter AuthListener to better represent User lifecycle
jsflax 57129ad
Update for Adams listener changes
jsflax 061a684
Merge branch 'master' of https://github.com/mongodb/stitch-android-sd…
jsflax cb374d9
Start unit tests
jsflax a5a27cf
Final touches
jsflax 128b01a
Add catch for admin db
jsflax bf75f79
Address not test comments
jsflax 3f99f46
More tests
jsflax ac543f9
Add rest of tests
jsflax 4c90c0e
Address changes
jsflax a711734
Appease linter
jsflax eb1e138
Add back in missing lock
jsflax 3400d44
Fix auth synchronization; appease linter
jsflax dca9ede
Fix sync synchronicity errors
jsflax 14217b4
Add server tests
jsflax fe9ddea
Read synchronized ids outside of lock, open stream
jsflax bab8c96
Rename switched to active user changed
jsflax 4c2fca7
Add disable listeners feature for unit tests
jsflax ca267f3
Appease linter
jsflax 508e6f6
Appease linter
jsflax 36aa4c0
Add extra lock on openStream
jsflax c970830
Lessen lock
jsflax c045cdc
Add interruptible streams
jsflax 660aacd
Add back in closed, fix broken unit tests
jsflax 17fae04
Added throws, removed stray prints
jsflax d6dad19
Ensure nsrunner is torn down properly
jsflax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
import com.mongodb.stitch.android.core.StitchAppClient; | ||
import com.mongodb.stitch.android.core.auth.StitchAuth; | ||
import com.mongodb.stitch.android.core.auth.StitchAuthListener; | ||
import com.mongodb.stitch.android.core.auth.StitchUser; | ||
import com.mongodb.stitch.android.core.auth.internal.StitchAuthImpl; | ||
import com.mongodb.stitch.android.core.internal.common.MainLooperDispatcher; | ||
import com.mongodb.stitch.android.core.internal.common.TaskDispatcher; | ||
|
@@ -31,12 +32,15 @@ | |
import com.mongodb.stitch.android.core.services.internal.StitchServiceClientImpl; | ||
import com.mongodb.stitch.core.StitchAppClientConfiguration; | ||
import com.mongodb.stitch.core.StitchAppClientInfo; | ||
import com.mongodb.stitch.core.auth.internal.CoreStitchAuth; | ||
import com.mongodb.stitch.core.internal.CoreStitchAppClient; | ||
import com.mongodb.stitch.core.internal.common.AuthMonitor; | ||
import com.mongodb.stitch.core.internal.net.StitchAppRequestClientImpl; | ||
import com.mongodb.stitch.core.internal.net.StitchAppRoutes; | ||
import com.mongodb.stitch.core.services.internal.AuthEvent; | ||
import com.mongodb.stitch.core.services.internal.CoreStitchServiceClient; | ||
import com.mongodb.stitch.core.services.internal.CoreStitchServiceClientImpl; | ||
import com.mongodb.stitch.core.services.internal.RebindEvent; | ||
|
||
import java.io.IOException; | ||
import java.lang.ref.WeakReference; | ||
|
@@ -271,8 +275,17 @@ public ResultT call() { | |
} | ||
|
||
@Override | ||
public boolean isLoggedIn() { | ||
return getAuth().isLoggedIn(); | ||
public boolean isLoggedIn() throws InterruptedException { | ||
return ((CoreStitchAuth)getAuth()).isLoggedInInterruptibly(); | ||
} | ||
|
||
@Override | ||
public boolean tryIsLoggedIn() { | ||
try { | ||
return ((CoreStitchAuth)getAuth()).isLoggedInInterruptibly(); | ||
} catch (InterruptedException e) { | ||
return false; | ||
} | ||
} | ||
|
||
@Nullable | ||
|
@@ -293,8 +306,7 @@ private void bindServiceClient(final CoreStitchServiceClient coreStitchServiceCl | |
this.serviceClients.add(new WeakReference<>(coreStitchServiceClient)); | ||
} | ||
|
||
@Override | ||
public void onAuthEvent(final StitchAuth auth) { | ||
private void onRebindEvent(final RebindEvent rebindEvent) { | ||
final Iterator<WeakReference<CoreStitchServiceClient>> iterator = | ||
this.serviceClients.iterator(); | ||
while (iterator.hasNext()) { | ||
|
@@ -305,11 +317,39 @@ public void onAuthEvent(final StitchAuth auth) { | |
if (binder == null) { | ||
this.serviceClients.remove(weakReference); | ||
} else { | ||
binder.onRebindEvent(); | ||
binder.onRebindEvent(rebindEvent); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void onAuthEvent(final StitchAuth auth) { | ||
} | ||
|
||
@Override | ||
public void onUserLoggedIn(final StitchAuth auth, | ||
final StitchUser loggedInUser) { | ||
onRebindEvent(new AuthEvent.UserLoggedIn<>(loggedInUser)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should you be rebinding on all of these? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is up to the service to determine what to do with the information given. |
||
} | ||
|
||
@Override | ||
public void onUserLoggedOut(final StitchAuth auth, | ||
final StitchUser loggedOutUser) { | ||
onRebindEvent(new AuthEvent.UserLoggedOut<>(loggedOutUser)); | ||
} | ||
|
||
@Override | ||
public void onActiveUserChanged(final StitchAuth auth, | ||
final StitchUser currentActiveUser, | ||
final @Nullable StitchUser previousActiveUser) { | ||
onRebindEvent(new AuthEvent.ActiveUserChanged<>(currentActiveUser, previousActiveUser)); | ||
} | ||
|
||
@Override | ||
public void onUserRemoved(final StitchAuth auth, final StitchUser removedUser) { | ||
onRebindEvent(new AuthEvent.UserRemoved<>(removedUser)); | ||
} | ||
|
||
/** | ||
* Closes the client and shuts down all background operations. | ||
*/ | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.