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+ println (result.successes().size.toString() + " successes, " + result.failures().size.toString() + " failures" )
35+ result.failures().forEach { failure ->
36+ println (" FAILURE: ${failure.name()} : ${failure.failureMessage()} " )
37+ // ...
38+ }
39+ }
40+ // [END android_examples_wfp_validation]
41+ }
42+
43+ private fun obtainTempWatchFaceFile (): File {
44+ val resourceName = " watchface.apk"
45+
46+ val inputStream = object {}.javaClass.classLoader.getResourceAsStream(resourceName)
47+
48+ if (inputStream == null ) {
49+ println (" Error: Cannot find resource '$resourceName '" )
50+ exitProcess(1 )
51+ }
52+
53+ val tempFile = File .createTempFile(" validator-" , " .apk" )
54+ tempFile.deleteOnExit()
55+
56+ FileOutputStream (tempFile).use { fos ->
57+ inputStream.copyTo(fos)
58+ }
59+ return tempFile
60+ }
0 commit comments