Skip to content

Adds Watch Face Push validation library snippet #555

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

Merged
merged 3 commits into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ protolayout = "1.3.0"
recyclerview = "1.4.0"
targetSdk = "34"
tiles = "1.5.0"
validatorPush = "1.0.0-alpha03"
version-catalog-update = "1.0.0"
wear = "1.3.0"
wearComposeFoundation = "1.5.0-beta04"
Expand Down Expand Up @@ -184,6 +185,7 @@ kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-t
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" }
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okHttp" }
play-services-wearable = { module = "com.google.android.gms:play-services-wearable", version.ref = "playServicesWearable" }
validator-push = { module = "com.google.android.wearable.watchface.validator:validator-push", version.ref = "validatorPush" }
wear-compose-material = { module = "androidx.wear.compose:compose-material", version.ref = "wearComposeMaterial" }
wear-compose-material3 = { module = "androidx.wear.compose:compose-material3", version.ref = "wearComposeMaterial3" }

Expand Down
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# * For validator: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
Expand Down
8 changes: 7 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ dependencyResolutionManagement {
println("https://androidx.dev/snapshots/builds/$it/artifacts/repository/")
maven { url = uri("https://androidx.dev/snapshots/builds/$it/artifacts/repository/") }
}

maven {
url = uri("https://jitpack.io")
content {
includeGroup("com.github.xgouchet")
}
}
google()
mavenCentral()
}
Expand All @@ -30,4 +35,5 @@ include(
":misc",
":identity:credentialmanager",
":xr",
":watchfacepush:validator"
)
1 change: 1 addition & 0 deletions watchfacepush/validator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
1 change: 1 addition & 0 deletions watchfacepush/validator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a sample project that contains the code snippets seen on https://developer.android.com/training/wearables/watch-face-push
31 changes: 31 additions & 0 deletions watchfacepush/validator/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

group = "com.example.validator"
version = "1.0"

plugins {
kotlin("jvm")
application
}

application {
mainClass.set("com.example.validator.Main")
}

dependencies {
implementation(libs.validator.push)
}
Empty file.
21 changes: 21 additions & 0 deletions watchfacepush/validator/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.example.validator

import com.google.android.wearable.watchface.validator.client.DwfValidatorFactory
import java.io.File
import java.io.FileOutputStream
import kotlin.system.exitProcess

class Main {
companion object {
@JvmStatic
fun main(args: Array<String>) {
println("Watch Face Push validator test program")
performValidation()
}
}
}

private fun performValidation() {
val watchFaceFile = obtainTempWatchFaceFile()
val appPackageName = "com.example.validator"

// [START android_examples_wfp_validation]
val validator = DwfValidatorFactory.create()
val result = validator.validate(watchFaceFile, appPackageName)

if (result.failures().isEmpty()) {
val token = result.validationToken()
println("Validation token: $token")

// Validation success - continue with the token
// ...
} else {
// There were failures, handle them accordingly - validation has failed.
result.failures().forEach { failure ->
println("FAILURE: ${failure.name()}: ${failure.failureMessage()}")
// ...
}
}
// [END android_examples_wfp_validation]
}

private fun obtainTempWatchFaceFile(): File {
val resourceName = "watchface.apk"

val inputStream = object {}.javaClass.classLoader.getResourceAsStream(resourceName)

if (inputStream == null) {
println("Error: Cannot find resource '$resourceName'")
exitProcess(1)
}

val tempFile = File.createTempFile("validator-", ".apk")
tempFile.deleteOnExit()

FileOutputStream(tempFile).use { fos ->
inputStream.copyTo(fos)
}
return tempFile
}
Binary file not shown.