diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 207fbcbf..a9abd1b8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" @@ -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" } diff --git a/gradlew b/gradlew index 1aa94a42..983fb2e9 100755 --- a/gradlew +++ b/gradlew @@ -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 -- \ diff --git a/settings.gradle.kts b/settings.gradle.kts index 6d2212b6..eb485975 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -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() } @@ -30,4 +35,5 @@ include( ":misc", ":identity:credentialmanager", ":xr", + ":watchfacepush:validator" ) diff --git a/watchfacepush/validator/.gitignore b/watchfacepush/validator/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/watchfacepush/validator/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/watchfacepush/validator/README.md b/watchfacepush/validator/README.md new file mode 100644 index 00000000..e11373aa --- /dev/null +++ b/watchfacepush/validator/README.md @@ -0,0 +1 @@ +This is a sample project that contains the code snippets seen on https://developer.android.com/training/wearables/watch-face-push diff --git a/watchfacepush/validator/build.gradle.kts b/watchfacepush/validator/build.gradle.kts new file mode 100644 index 00000000..66cb693b --- /dev/null +++ b/watchfacepush/validator/build.gradle.kts @@ -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) +} \ No newline at end of file diff --git a/watchfacepush/validator/consumer-rules.pro b/watchfacepush/validator/consumer-rules.pro new file mode 100644 index 00000000..e69de29b diff --git a/watchfacepush/validator/proguard-rules.pro b/watchfacepush/validator/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/watchfacepush/validator/proguard-rules.pro @@ -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 \ No newline at end of file diff --git a/watchfacepush/validator/src/main/kotlin/com/example/validator/Main.kt b/watchfacepush/validator/src/main/kotlin/com/example/validator/Main.kt new file mode 100644 index 00000000..f046ebe0 --- /dev/null +++ b/watchfacepush/validator/src/main/kotlin/com/example/validator/Main.kt @@ -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) { + 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 +} \ No newline at end of file diff --git a/watchfacepush/validator/src/main/resources/watchface.apk b/watchfacepush/validator/src/main/resources/watchface.apk new file mode 100644 index 00000000..d9bd51c3 Binary files /dev/null and b/watchfacepush/validator/src/main/resources/watchface.apk differ