-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Completely rewrite CredentialsApiHelper.java and hopefully fix memory leak #566
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
Signed-off-by: Alex Saveau <[email protected]>
|
||
public static int getSafeAutoManageId() { | ||
IDS.add(null); | ||
return IDS.size() - 1; |
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.
This is sooooo much better than my previous solution. 😄
* API. | ||
*/ | ||
@Deprecated | ||
public class OldCredentialsApiHelper { |
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.
You don't need to look here, I just copied this from the old CredentialsApiHelper
.
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.
Let's pick a better name for this, maybe ActivityCredentialsApiHelper
or something. "Old" as a prefix does not help to show what was wrong with it.
Also I'd argue that we should keep this class named CredentialsApiHelper
and the new class is the one that should have a new name since it reduces churn.
*/ | ||
@Deprecated | ||
public Task<Void> signOut(@NonNull Activity activity) { |
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.
This makes me so happy: because our new signOut
method uses FragmentActivity
which extends Activity
, people will be automatically upgraded. How's that for customer service! 😄
import java.util.List; | ||
|
||
public class GoogleApiHelper { | ||
private static final List<Void> IDS = new ArrayList<>(); |
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 think this would do better as an AtomicInteger
and then your static function would just be wrapping incrementAndGet()
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.
@samtstern Never knew that existed, sounds awesome!
*/ | ||
@Deprecated | ||
public Task<Void> delete(@NonNull Activity activity) { |
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.
As far as I can tell the difference between delete(FragmentActivity)
and delete(Activity)
is just that the former uses CredentialApiHelper
and the latter uses OldCredentialApiHelper
.
Could this all be simplified by having both of the CredentialApiHelper
classes implement a common interface? I think it would look like this:
interface CredentialApiHelper {
Task<Status> delete(Credential credential);
Task<Status> disableAuthSignIn();
}
And then these two delete()
functions would just be a matter of constructing the proper Helper
and then calling to a private Task<Void> delete(CredentialApiHelper helper)
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.
@samtstern To address this comment and this one, I didn't add an interface or a good name because my intention for us to throw this away in FBUI v2.0
. Do you disagree with that? If so, then we should definitely clean things up and maybe undeprecate thoses classes. What do you think?
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.
2.0 could be a while away, let's try and keep things clean in the meantime.
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.
@samtstern SGTM, I'll leave things deprecated so we know to remove that stuff if we go that route, but I keep things clean in the meantime.
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
@samtstern I'm happy with it now, PTAL. |
CredentialApiHelper credentialHelper = CredentialsApiHelper.getInstance(gacHelper); | ||
|
||
// Get all SmartLock credentials associated with the user | ||
List<Credential> credentials = SmartLockBase.credentialsFromFirebaseUser(firebaseUser); |
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.
From here down to the end of the function seems duplicated between the two delete()
methods. Can we abstract into a common private method?
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.
Yup, forgot to refactor that.
Signed-off-by: Alex Saveau <[email protected]>
@@ -31,7 +31,8 @@ | |||
* A {@link com.google.android.gms.tasks.Task Task} based wrapper for the Smart Lock for Passwords | |||
* API. | |||
*/ | |||
public class CredentialsApiHelper { | |||
@Deprecated | |||
public class CredentialsApiHelper implements CredentialApiHelper { |
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.
One last (annoying) comment: it's pretty confusing to have these two names only differ by an 's' in the middle. Let's change the name of the interface? Maybe CredentialTaskApi
or something like that.
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.
@samtstern SGTM, I just can't wait for us to throw this stuff away anyway.
Signed-off-by: Alex Saveau <[email protected]>
|
||
public Task<Status> signOut() { | ||
final TaskCompletionSource<Status> statusTask = new TaskCompletionSource<>(); | ||
getConnectedApiTask().addOnSuccessListener(new OnSuccessListener<Bundle>() { |
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.
Missed this, but shouldn't we also add an onFailureListener
to getConnectedApiTask()
that propagates the failure to statusTask
through setException
?
credentialsApiHelper.delete(mCredential) | ||
.addOnCompleteListener(new OnCompleteListener<Status>() { | ||
AuthUI.getInstance() | ||
.delete(getActivity()) |
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.
This now also deletes the underlying Firebase Auth account in addition to deleting the credentials. This has two new properties:
- Will fail if there is no currently signed in user
- Will fail if we don't have recent authentication (last 5 minutes)
Did you intend to change this behavior?
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
@samtstern Sorry about those mistakes, please let me take another look at this PR to make sure I didn't mess up again. And maybe you could take another look too? (I've been distracted by my other PRs 😄) |
Signed-off-by: Alex Saveau <[email protected]>
@samtstern Ok, I think it's all good now. |
@@ -26,7 +25,7 @@ public static GoogleSignInHelper getInstance(FragmentActivity activity) { | |||
|
|||
public Task<Status> signOut() { | |||
final TaskCompletionSource<Status> statusTask = new TaskCompletionSource<>(); | |||
getConnectedApiTask().addOnSuccessListener(new OnSuccessListener<Bundle>() { | |||
getConnectedApiTask().addOnSuccessListener(new ExceptionForwarder<Bundle>(statusTask) { |
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 think this will work, it's still setting the ExceptionForwarder
using addOnSuccessListener
so even though it implements onFailure
that will never be called.
You may want to make this an onCompleteListener
instance instead so you'll get notified of success or failure.
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.
@samtstern Today's not my day with tasks! 😵 PTAL at 15fbed3, I'm pretty sure that will work.
|
||
public Task<Status> signOut() { | ||
final TaskCompletionSource<Status> statusTask = new TaskCompletionSource<>(); | ||
getConnectedApiTask().addOnSuccessListener(new ExceptionForwarder<Bundle>(statusTask) { |
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 think this will work, it's still setting the ExceptionForwarder using addOnSuccessListener so even though it implements onFailure that will never be called.
You may want to make this an onCompleteListener instance instead so you'll get notified of success or failure.
Signed-off-by: Alex Saveau <[email protected]>
Woohoo looks good! I will merge once tests pass. |
@samtstern OMG finally! Thanks for sticking with me on this one! 😄 |
@samtstern This should fix the memory leak because we aren't storing the activity anywhere.
#561