Skip to content

Commit b1d1297

Browse files
committed
refactor(auth): log an exception if the device has no browser installed (#2055)
1 parent aa5282e commit b1d1297

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

auth/src/main/AndroidManifest.xml

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
88
<uses-permission android:name="android.permission.INTERNET" />
99

10+
<!-- Used to check if a browser is available before launching phone auth -->
11+
<!-- See ui/phone/PhoneNumberVerificationHandler.isBrowserAvailable() -->
12+
<queries>
13+
<intent>
14+
<action android:name="android.intent.action.VIEW" />
15+
<category android:name="android.intent.category.BROWSABLE" />
16+
<data android:scheme="http" />
17+
</intent>
18+
</queries>
19+
1020
<application>
1121

1222
<meta-data

auth/src/main/java/com/firebase/ui/auth/ui/phone/PhoneNumberVerificationHandler.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import android.app.Activity;
44
import android.app.Application;
5+
import android.content.ActivityNotFoundException;
6+
import android.content.Intent;
7+
import android.net.Uri;
58
import android.os.Bundle;
6-
79
import com.firebase.ui.auth.data.model.PhoneNumberVerificationRequiredException;
810
import com.firebase.ui.auth.data.model.Resource;
911
import com.firebase.ui.auth.viewmodel.AuthViewModelBase;
@@ -58,7 +60,11 @@ public void onCodeSent(@NonNull String verificationId,
5860
if (force) {
5961
optionsBuilder.setForceResendingToken(mForceResendingToken);
6062
}
61-
PhoneAuthProvider.verifyPhoneNumber(optionsBuilder.build());
63+
if (isBrowserAvailable(activity)) {
64+
PhoneAuthProvider.verifyPhoneNumber(optionsBuilder.build());
65+
} else {
66+
setResult(Resource.forFailure(new ActivityNotFoundException("No browser was found in this device")));
67+
}
6268
}
6369

6470
public void submitVerificationCode(String number, String code) {
@@ -77,4 +83,9 @@ public void onRestoreInstanceState(@Nullable Bundle savedInstanceState) {
7783
mVerificationId = savedInstanceState.getString(VERIFICATION_ID_KEY);
7884
}
7985
}
86+
87+
private boolean isBrowserAvailable(Activity activity) {
88+
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://"));
89+
return browserIntent.resolveActivity(activity.getPackageManager()) != null;
90+
}
8091
}

0 commit comments

Comments
 (0)