Skip to content

Commit fbf703a

Browse files
Merge pull request #358 from Ayush0Chaudhary/login-crash-detect
Add crashylytics for the login
2 parents a8602c6 + abd1860 commit fbf703a

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

app/src/main/java/com/blurr/voice/LoginActivity.kt.kt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.google.firebase.Firebase
2424
import com.google.firebase.auth.FirebaseAuth
2525
import com.google.firebase.auth.GoogleAuthProvider
2626
import com.google.firebase.auth.auth
27+
import com.google.firebase.crashlytics.FirebaseCrashlytics
2728
import kotlinx.coroutines.launch
2829

2930
class LoginActivity : AppCompatActivity() {
@@ -83,6 +84,8 @@ class LoginActivity : AppCompatActivity() {
8384
}
8485
} catch (e: ApiException) {
8586
Log.w("LoginActivity", "Google sign in failed", e)
87+
FirebaseCrashlytics.getInstance().recordException(e)
88+
FirebaseCrashlytics.getInstance().log("Google Sign-In failed in credential extraction with ApiException")
8689
Toast.makeText(this, "Google Sign-In failed.", Toast.LENGTH_SHORT).show()
8790
progressBar.visibility = View.GONE
8891
loadingText.visibility = View.GONE
@@ -103,23 +106,33 @@ class LoginActivity : AppCompatActivity() {
103106
private fun signIn() {
104107
progressBar.visibility = View.VISIBLE
105108
loadingText.visibility = View.VISIBLE
109+
110+
Log.d("LoginActivity", "Starting Google Sign-In process")
111+
Log.d("LoginActivity", "Using web client ID: ${getString(R.string.default_web_client_id)}")
112+
106113
// 4. Launch the sign-in flow
107114
oneTapClient.beginSignIn(signInRequest)
108115
.addOnSuccessListener(this) { result ->
109116
try {
117+
Log.d("LoginActivity", "One Tap UI started successfully")
110118
// The BeginSignInResult contains a PendingIntent
111119
val intentSenderRequest = IntentSenderRequest.Builder(result.pendingIntent.intentSender).build()
112120
// Launch the intent sender
113121
googleSignInLauncher.launch(intentSenderRequest)
114122
} catch (e: Exception) {
115-
Log.e("LoginActivity", "Couldn't start One Tap UI: ${e.localizedMessage}")
123+
Log.e("LoginActivity", "Couldn't start One Tap UI: ${e.localizedMessage}", e)
124+
FirebaseCrashlytics.getInstance().recordException(e)
125+
FirebaseCrashlytics.getInstance().log("Failed to start One Tap UI: ${e.localizedMessage}")
126+
Toast.makeText(this, "Sign-in UI failed to start: ${e.localizedMessage}", Toast.LENGTH_LONG).show()
116127
progressBar.visibility = View.GONE
117128
loadingText.visibility = View.GONE
118129
}
119130
}
120131
.addOnFailureListener(this) { e ->
121-
Log.e("LoginActivity", "Sign-in failed: ${e.localizedMessage}")
122-
Toast.makeText(this, "Sign-in failed. Please try again.", Toast.LENGTH_SHORT).show()
132+
Log.e("LoginActivity", "Sign-in failed: ${e.localizedMessage}", e)
133+
FirebaseCrashlytics.getInstance().recordException(e)
134+
FirebaseCrashlytics.getInstance().log("Google One Tap sign-in failed: ${e.localizedMessage}")
135+
Toast.makeText(this, "Sign-in failed: ${e.localizedMessage}", Toast.LENGTH_LONG).show()
123136
progressBar.visibility = View.GONE
124137
loadingText.visibility = View.GONE
125138
}
@@ -176,6 +189,10 @@ class LoginActivity : AppCompatActivity() {
176189
}
177190
} else {
178191
Log.w("LoginActivity", "signInWithCredential:failure", task.exception)
192+
task.exception?.let { exception ->
193+
FirebaseCrashlytics.getInstance().recordException(exception)
194+
FirebaseCrashlytics.getInstance().log("Firebase authentication failed: ${exception.localizedMessage}")
195+
}
179196
Toast.makeText(this, "Authentication Failed.", Toast.LENGTH_SHORT).show()
180197
}
181198
}

app/src/main/res/values/strings.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,4 @@
119119

120120
<string name="microphone_permission_not_granted">Microphone permission not granted</string>
121121
<string name="accessibility_permission_needed_for_task">Hey, accessibility permission is needed to execute any task. I know you might have doubt giving this permission to me, but my code is open source, so can always check it out if you have doubts.</string>
122-
123122
</resources>

0 commit comments

Comments
 (0)