Don't log full exception with no Wear app installed (#3031)

- If no Wear app is installed on a device, checking for nodes will throw an exception that the API is unavailable. This is an expected error, don't log it to not confuse users.
This commit is contained in:
Joris Pelgröm 2022-11-03 17:30:31 +01:00 committed by GitHub
parent 3b93bc1860
commit 150f919a1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,6 +2,8 @@ package io.homeassistant.companion.android.settings.wear
import android.content.Context
import android.util.Log
import com.google.android.gms.common.api.ApiException
import com.google.android.gms.common.api.CommonStatusCodes
import com.google.android.gms.wearable.Wearable
import kotlinx.coroutines.tasks.await
@ -18,7 +20,12 @@ object SettingsWearDetection {
val nodeClient = Wearable.getNodeClient(context)
nodeClient.connectedNodes.await().any()
} catch (e: Exception) {
Log.e(TAG, "Exception while discovering nodes", e)
if (e is ApiException && e.statusCode == CommonStatusCodes.API_NOT_CONNECTED && e.message?.contains("API_UNAVAILABLE") == true) {
// Wearable.API is not available on this device.
Log.d(TAG, "API unavailable for discovering nodes (no Wear)",)
} else {
Log.e(TAG, "Exception while discovering nodes", e)
}
false
}
}