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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve TokenBundleRepositoryImpl to check if API is available #1089

Merged
merged 1 commit into from
Mar 11, 2023

Conversation

luizgrp
Copy link
Member

@luizgrp luizgrp commented Mar 10, 2023

WHAT

Improve TokenBundleRepositoryImpl to check if DataClient API is available.

WHY

In order to handle the following exception when device doesn't have the API available:

com.google.android.gms.common.api.ApiException: 17: API: Wearable.API is not available on this device.

HOW

  • Delay creation of DataStore in TokenBundleRepositoryImpl until update function is called;
  • Change update to check for api availability and fail silently when not available;
  • Add isAvailable function to TokenBundleRepository so developers can check if the repository can be used on the device running;
  • Improve sample app to show usage of new function;

Checklist 馃搵

  • Add explicit visibility modifier and explicit return types for public declarations
  • Run spotless check
  • Run tests
  • Update metalava's signature text files

@luizgrp luizgrp self-assigned this Mar 10, 2023
@luizgrp luizgrp force-pushed the authdataphone_improve_tokenbundlerepo branch from c57ca48 to c002461 Compare March 10, 2023 17:36
@luizgrp luizgrp requested a review from yschimke March 10, 2023 18:03
@@ -75,7 +84,16 @@ class MainActivity : ComponentActivity() {
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
val coroutineScope = rememberCoroutineScope()
var apiAvailable by remember { mutableStateOf(false) }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's safe to do the operations, then I think defaulting to true. Or making this true/false/null would be better here. Avoid glitching the screen in the hopefully typical case where it is available.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it makes sense, and it would be better to have this in a VM, and have proper states

this sample app is very simple, in comparison to the wear counterpart, it's in my plans to improve it further and will address it together

override suspend fun isAvailable(): Boolean {
return try {
GoogleApiAvailability.getInstance()
.checkApiAvailability(registry.dataClient)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure you like the God object of the registry, but if we push this up there, then it can be done once, at startup meaning it's immediately available so screen can draw correctly immediately.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be ideal to have these checks in WearDataLayerRegistry, not sure about having it immediately available, it would be an assumption about the time taken by play service lib to check it

raised #1091

@luizgrp luizgrp merged commit 9cb3879 into google:main Mar 11, 2023
@luizgrp luizgrp deleted the authdataphone_improve_tokenbundlerepo branch March 11, 2023 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants