-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix broken play services checks #462
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
Changes from 2 commits
a59b111
89add90
2361932
a57fdf3
a289a01
53a99f7
6bf3220
c056b0f
e2b195d
659bc5f
c05964e
ca699bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,96 @@ | ||
package com.firebase.ui.auth; | ||
|
||
import android.app.Dialog; | ||
import android.content.Context; | ||
import android.content.DialogInterface; | ||
import android.content.Intent; | ||
import android.net.ConnectivityManager; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
|
||
import com.firebase.ui.auth.ui.ActivityHelper; | ||
import com.firebase.ui.auth.ui.AppCompatBase; | ||
import com.firebase.ui.auth.ui.ExtraConstants; | ||
import com.firebase.ui.auth.ui.FlowParameters; | ||
import com.firebase.ui.auth.util.signincontainer.SignInDelegate; | ||
import com.google.android.gms.common.GoogleApiAvailability; | ||
|
||
public class KickoffActivity extends AppCompatBase { | ||
private static final String TAG = "KickoffActivity"; | ||
private static final int RC_PLAY_SERVICES = 1; | ||
|
||
private boolean mIsWaitingForPlayServices = false; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstance) { | ||
super.onCreate(savedInstance); | ||
if (savedInstance == null) { | ||
SignInDelegate.delegate(this, mActivityHelper.getFlowParams()); | ||
if (savedInstance == null || !savedInstance.getBoolean(ExtraConstants.HAS_EXISTING_INSTANCE)) { | ||
if (!hasNetworkConnection()) { | ||
Log.d(TAG, "No network connection"); | ||
finish(ErrorCodes.NO_NETWORK, IdpResponse.getErrorCodeIntent(ErrorCodes.NO_NETWORK)); | ||
return; | ||
} | ||
|
||
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance(); | ||
Dialog errorDialog = apiAvailability.getErrorDialog( | ||
this, | ||
apiAvailability.isGooglePlayServicesAvailable(this), | ||
RC_PLAY_SERVICES, | ||
new DialogInterface.OnCancelListener() { | ||
@Override | ||
public void onCancel(DialogInterface dialog) { | ||
finish(ResultCodes.CANCELED, new Intent()); | ||
} | ||
}); | ||
|
||
// The error dialog will be null if isGooglePlayServicesAvailable returned SUCCESS | ||
if (errorDialog == null) { | ||
SignInDelegate.delegate(KickoffActivity.this, | ||
mActivityHelper.getFlowParams()); | ||
} else { | ||
errorDialog.show(); | ||
mIsWaitingForPlayServices = true; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void onSaveInstanceState(Bundle outState) { | ||
// It doesn't matter what we put here, we just don't want outState to be empty | ||
outState.putBoolean(ExtraConstants.HAS_EXISTING_INSTANCE, true); | ||
outState.putBoolean(ExtraConstants.HAS_EXISTING_INSTANCE, !mIsWaitingForPlayServices); | ||
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. The use of Can we do two separate extras? One which is always |
||
super.onSaveInstanceState(outState); | ||
} | ||
|
||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
super.onActivityResult(requestCode, resultCode, data); | ||
SignInDelegate delegate = SignInDelegate.getInstance(this); | ||
if (delegate != null) { | ||
delegate.onActivityResult(requestCode, resultCode, data); | ||
if (requestCode == RC_PLAY_SERVICES) { | ||
if (resultCode == ResultCodes.OK) { | ||
SignInDelegate.delegate(KickoffActivity.this, | ||
mActivityHelper.getFlowParams()); | ||
} else { | ||
finish(ResultCodes.CANCELED, | ||
IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR)); | ||
} | ||
} else { | ||
SignInDelegate delegate = SignInDelegate.getInstance(this); | ||
if (delegate != null) delegate.onActivityResult(requestCode, resultCode, data); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Check if there is an active or soon-to-be-active network connection. | ||
*/ | ||
private boolean hasNetworkConnection() { | ||
ConnectivityManager manager = | ||
(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); | ||
|
||
return manager != null | ||
&& manager.getActiveNetworkInfo() != null | ||
&& manager.getActiveNetworkInfo().isConnectedOrConnecting(); | ||
} | ||
|
||
public static Intent createIntent(Context context, FlowParameters flowParams) { | ||
return ActivityHelper.createBaseIntent(context, KickoffActivity.class, flowParams); | ||
} | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,6 @@ | |
import com.firebase.ui.auth.ui.FlowParameters; | ||
import com.firebase.ui.auth.ui.FragmentHelper; | ||
import com.firebase.ui.auth.util.GoogleApiConstants; | ||
import com.firebase.ui.auth.util.PlayServicesHelper; | ||
import com.google.android.gms.auth.api.Auth; | ||
import com.google.android.gms.auth.api.credentials.Credential; | ||
import com.google.android.gms.common.ConnectionResult; | ||
|
@@ -169,9 +168,7 @@ private void finish() { | |
public void saveCredentialsOrFinish(FirebaseUser firebaseUser, | ||
@Nullable String password, | ||
@Nullable IdpResponse response) { | ||
if (!mHelper.getFlowParams().smartLockEnabled | ||
|| !PlayServicesHelper.getInstance(getContext()).isPlayServicesAvailable() | ||
|| getActivity().isFinishing()) { | ||
if (!mHelper.getFlowParams().smartLockEnabled || getActivity().isFinishing()) { | ||
finish(); | ||
return; | ||
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. @samtstern Is there a reason for keeping this here? Since 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. That should be true, fine with your new change. |
||
} | ||
|
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.
Although you're getting rid of
PlayServicesHelper
I'd still like to centralize all Play services availability logic somewhere. Even if the class is just a host for a singleton ofGoogleApiAvailability
that's a win for future testing. Play services has given me a lot of trouble in testing (although you seem to have simplified a lot of it here).