Skip to content

Commit c9e37f8

Browse files
authored
Adds Watch Face Push validation library snippet (#555)
* Adds Watch Face Push validation library snippet * Removed jar * Removes unnecessary statement
1 parent cafc3dd commit c9e37f8

File tree

10 files changed

+123
-2
lines changed

10 files changed

+123
-2
lines changed

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ protolayout = "1.3.0"
6969
recyclerview = "1.4.0"
7070
targetSdk = "34"
7171
tiles = "1.5.0"
72+
validatorPush = "1.0.0-alpha03"
7273
version-catalog-update = "1.0.0"
7374
wear = "1.3.0"
7475
wearComposeFoundation = "1.5.0-beta04"
@@ -184,6 +185,7 @@ kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-t
184185
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" }
185186
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okHttp" }
186187
play-services-wearable = { module = "com.google.android.gms:play-services-wearable", version.ref = "playServicesWearable" }
188+
validator-push = { module = "com.google.android.wearable.watchface.validator:validator-push", version.ref = "validatorPush" }
187189
wear-compose-material = { module = "androidx.wear.compose:compose-material", version.ref = "wearComposeMaterial" }
188190
wear-compose-material3 = { module = "androidx.wear.compose:compose-material3", version.ref = "wearComposeMaterial3" }
189191

gradlew

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

211211
set -- \

settings.gradle.kts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ dependencyResolutionManagement {
1414
println("https://androidx.dev/snapshots/builds/$it/artifacts/repository/")
1515
maven { url = uri("https://androidx.dev/snapshots/builds/$it/artifacts/repository/") }
1616
}
17-
17+
maven {
18+
url = uri("https://jitpack.io")
19+
content {
20+
includeGroup("com.github.xgouchet")
21+
}
22+
}
1823
google()
1924
mavenCentral()
2025
}
@@ -30,4 +35,5 @@ include(
3035
":misc",
3136
":identity:credentialmanager",
3237
":xr",
38+
":watchfacepush:validator"
3339
)

watchfacepush/validator/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

watchfacepush/validator/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a sample project that contains the code snippets seen on https://developer.android.com/training/wearables/watch-face-push
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2022 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
group = "com.example.validator"
18+
version = "1.0"
19+
20+
plugins {
21+
kotlin("jvm")
22+
application
23+
}
24+
25+
application {
26+
mainClass.set("com.example.validator.Main")
27+
}
28+
29+
dependencies {
30+
implementation(libs.validator.push)
31+
}

watchfacepush/validator/consumer-rules.pro

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.example.validator
2+
3+
import com.google.android.wearable.watchface.validator.client.DwfValidatorFactory
4+
import java.io.File
5+
import java.io.FileOutputStream
6+
import kotlin.system.exitProcess
7+
8+
class Main {
9+
companion object {
10+
@JvmStatic
11+
fun main(args: Array<String>) {
12+
println("Watch Face Push validator test program")
13+
performValidation()
14+
}
15+
}
16+
}
17+
18+
private fun performValidation() {
19+
val watchFaceFile = obtainTempWatchFaceFile()
20+
val appPackageName = "com.example.validator"
21+
22+
// [START android_examples_wfp_validation]
23+
val validator = DwfValidatorFactory.create()
24+
val result = validator.validate(watchFaceFile, appPackageName)
25+
26+
if (result.failures().isEmpty()) {
27+
val token = result.validationToken()
28+
println("Validation token: $token")
29+
30+
// Validation success - continue with the token
31+
// ...
32+
} else {
33+
// There were failures, handle them accordingly - validation has failed.
34+
result.failures().forEach { failure ->
35+
println("FAILURE: ${failure.name()}: ${failure.failureMessage()}")
36+
// ...
37+
}
38+
}
39+
// [END android_examples_wfp_validation]
40+
}
41+
42+
private fun obtainTempWatchFaceFile(): File {
43+
val resourceName = "watchface.apk"
44+
45+
val inputStream = object {}.javaClass.classLoader.getResourceAsStream(resourceName)
46+
47+
if (inputStream == null) {
48+
println("Error: Cannot find resource '$resourceName'")
49+
exitProcess(1)
50+
}
51+
52+
val tempFile = File.createTempFile("validator-", ".apk")
53+
tempFile.deleteOnExit()
54+
55+
FileOutputStream(tempFile).use { fos ->
56+
inputStream.copyTo(fos)
57+
}
58+
return tempFile
59+
}
Binary file not shown.

0 commit comments

Comments
 (0)