Skip to content

Commit

Permalink
refactor(auth): log an exception if the device has no browser install…
Browse files Browse the repository at this point in the history
…ed (#2055)
  • Loading branch information
thatfiredev authored Aug 19, 2022
1 parent 12ec27b commit e7a7053
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
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")));
}
}

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;
}
}

0 comments on commit e7a7053

Please sign in to comment.