-
Notifications
You must be signed in to change notification settings - Fork 120
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
Google Play Service error handle #2900
Closed
Closed
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9cb3022
play service error handle
anandwana001 ab57bdc
check fix
anandwana001 08035c3
remove timber
anandwana001 969589d
added log
anandwana001 3aed8f3
nit fix
anandwana001 3128993
Merge branch 'master' into anandwana001/2783/handle-googleplay-service
anandwana001 31a2a4e
suggested fix
anandwana001 4d9326d
Merge remote-tracking branch 'origin/anandwana001/2783/handle-googlep…
anandwana001 0acdcc4
Update GoogleApiManager.kt
gino-m 416cbcd
suggested fix
anandwana001 4e9b53a
more helpful log message
anandwana001 19116ef
Merge branch 'master' into anandwana001/2783/handle-googleplay-service
anandwana001 dde8f5b
Merge branch 'master' into anandwana001/2783/handle-googleplay-service
anandwana001 685d5e6
revert
anandwana001 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
import timber.log.Timber | ||
|
||
private val INSTALL_API_REQUEST_CODE = GoogleApiAvailability::class.java.hashCode() and 0xffff | ||
|
||
|
@@ -37,29 +38,30 @@ | |
* Displays a dialog to install Google Play Services, if missing. Throws an error if install not | ||
* possible or cancelled. | ||
*/ | ||
suspend fun installGooglePlayServices() { | ||
suspend fun installGooglePlayServices(): Boolean { | ||
val status = googleApiAvailability.isGooglePlayServicesAvailable(context) | ||
if (status == ConnectionResult.SUCCESS) return | ||
if (status == ConnectionResult.SUCCESS) return true | ||
|
||
val requestCode = INSTALL_API_REQUEST_CODE | ||
startResolution(status, requestCode, GooglePlayServicesMissingException()) | ||
getNextResult(requestCode) | ||
return startResolution(status, requestCode) | ||
} | ||
|
||
private fun startResolution(status: Int, requestCode: Int, throwable: Throwable) { | ||
if (!googleApiAvailability.isUserResolvableError(status)) throw throwable | ||
private suspend fun startResolution(status: Int, requestCode: Int): Boolean { | ||
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. Same comment here. |
||
if (!googleApiAvailability.isUserResolvableError(status)) return false | ||
|
||
activityStreams.withActivity { | ||
googleApiAvailability.showErrorDialogFragment(it, status, requestCode) { throw throwable } | ||
return try { | ||
activityStreams.withActivity { activity -> | ||
googleApiAvailability.showErrorDialogFragment(activity, status, requestCode, null) | ||
} | ||
getNextResult(requestCode) | ||
} catch (e: Exception) { | ||
anandwana001 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Timber.e("Activity result was not successful for requestCode: $requestCode") | ||
anandwana001 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
false | ||
} | ||
} | ||
|
||
private suspend fun getNextResult(requestCode: Int) { | ||
private suspend fun getNextResult(requestCode: Int): Boolean { | ||
anandwana001 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
val result = activityStreams.getNextActivityResult(requestCode) | ||
if (!result.isOk()) { | ||
error("Activity result failed: requestCode = $requestCode, result = $result") | ||
} | ||
return result.isOk() | ||
} | ||
|
||
class GooglePlayServicesMissingException : Error("Google play services not available") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,8 +28,12 @@ internal constructor( | |
) : AbstractViewModel() { | ||
|
||
/** Checks & installs Google Play Services and initializes the login flow. */ | ||
suspend fun initializeLogin() { | ||
googleApiManager.installGooglePlayServices() | ||
suspend fun initializeLogin(): Boolean { | ||
val isGooglePlayServicesAvailable = googleApiManager.installGooglePlayServices() | ||
if (!isGooglePlayServicesAvailable) { | ||
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. Same comment here. This entire condition goes away if |
||
return false | ||
} | ||
userRepository.init() | ||
return true | ||
anandwana001 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Adding a
Boolean
return value means the caller needs to address both return value and thrown exceptions as failure states. Since we need to catch exceptions anyway, why not rely on those for error states?