Skip to content
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

refactor(auth): log an exception if the device has no browser installed #2055

Merged
merged 2 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions auth/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

<!-- Used to check if a browser is available before launching phone auth -->
<!-- See ui/phone/PhoneNumberVerificationHandler.isBrowserAvailable() -->
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
</intent>
</queries>

<application>

<meta-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import android.app.Activity;
import android.app.Application;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

import com.firebase.ui.auth.data.model.PhoneNumberVerificationRequiredException;
import com.firebase.ui.auth.data.model.Resource;
import com.firebase.ui.auth.viewmodel.AuthViewModelBase;
Expand Down Expand Up @@ -58,7 +60,11 @@ public void onCodeSent(@NonNull String verificationId,
if (force) {
optionsBuilder.setForceResendingToken(mForceResendingToken);
}
PhoneAuthProvider.verifyPhoneNumber(optionsBuilder.build());
if (isBrowserAvailable(activity)) {
PhoneAuthProvider.verifyPhoneNumber(optionsBuilder.build());
} else {
setResult(Resource.forFailure(new ActivityNotFoundException("No browser was found in this device")));
marinacoelho marked this conversation as resolved.
Show resolved Hide resolved
}
}

public void submitVerificationCode(String number, String code) {
Expand All @@ -77,4 +83,9 @@ public void onRestoreInstanceState(@Nullable Bundle savedInstanceState) {
mVerificationId = savedInstanceState.getString(VERIFICATION_ID_KEY);
}
}

private boolean isBrowserAvailable(Activity activity) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://"));
return browserIntent.resolveActivity(activity.getPackageManager()) != null;
}
}