diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8023960..55ba232 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,18 +13,18 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '17' distribution: 'temurin' - name: Validate Gradle Wrapper - uses: gradle/wrapper-validation-action@v1 + uses: gradle/wrapper-validation-action@v3 - - uses: gradle/gradle-build-action@v2 + - uses: gradle/gradle-build-action@v3 - name: Build and run tests run: ./gradlew build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f37111f..9006770 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,5 +1,5 @@ name: Release -run-name: ${{ format('Release version {0}', inputs.version)}} by @${{ github.actor }} +run-name: ${{ format('Release version {0}', inputs.version)}} by @${{ github.actor }} on: workflow_dispatch: @@ -28,7 +28,7 @@ jobs: uses: actions/checkout@v4 - name: Set up JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '17' distribution: 'temurin' @@ -48,7 +48,7 @@ jobs: - name: Validate Gradle Wrapper uses: gradle/wrapper-validation-action@v1 - - uses: gradle/gradle-build-action@v2 + - uses: gradle/gradle-build-action@v3 with: # Disable writing to cache. Don't want to spoil the main cache cache-read-only: true @@ -95,7 +95,7 @@ jobs: rm gradle.properties.bak - name: GitHub Release - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 with: generate_release_notes: true tag_name: v${{ inputs.version }} diff --git a/build.gradle b/build.gradle index 82d19fd..b89fb89 100644 --- a/build.gradle +++ b/build.gradle @@ -1,17 +1,18 @@ buildscript { ext { - compose_ui_version = '1.4.0' + compose_ui_version = '1.5.0' } } + // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id 'com.android.application' version '8.2.2' apply false - id 'com.android.library' version '8.2.2' apply false - id 'org.jetbrains.kotlin.android' version '1.9.20' apply false - id 'org.jetbrains.dokka' version '1.9.10' apply false - id 'com.vanniktech.maven.publish' version "0.25.1" apply false + alias libs.plugins.androidApplication apply false + alias libs.plugins.androidLibrary apply false + alias libs.plugins.kotlinAndroid apply false + alias libs.plugins.dokka apply false + alias libs.plugins.mavenPublish apply false - id 'com.diffplug.spotless' version "6.19.0" + alias libs.plugins.spotless } subprojects { @@ -19,9 +20,11 @@ subprojects { spotless { kotlin { target("src/**/*.kt") - targetExclude("$buildDir/**/*") - targetExclude("bin/**/*") ktlint() + .editorConfigOverride([ + 'ktlint_standard_property-naming': 'disabled', + 'ktlint_function_naming_ignore_when_annotated_with': 'Composable' + ]) } } } diff --git a/common.gradle b/common.gradle index ffe1aa0..54c0827 100644 --- a/common.gradle +++ b/common.gradle @@ -38,8 +38,8 @@ android { } dependencies { - implementation 'androidx.core:core-ktx:1.12.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3' + implementation(libs.core.ktx) + implementation(libs.kotlinx.coroutines) - testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3' + testImplementation(libs.kotlinx.coroutines.test) } diff --git a/dev-app/build.gradle b/dev-app/build.gradle index 2beb1b6..98ddb78 100644 --- a/dev-app/build.gradle +++ b/dev-app/build.gradle @@ -1,6 +1,6 @@ plugins { - id 'com.android.application' - id 'org.jetbrains.kotlin.android' + alias libs.plugins.androidApplication + alias libs.plugins.kotlinAndroid } apply from: rootProject.file("$rootDir/common.gradle") @@ -32,7 +32,7 @@ android { } composeOptions { - kotlinCompilerExtensionVersion '1.5.5' + kotlinCompilerExtensionVersion '1.5.12' } lint { @@ -43,17 +43,17 @@ android { dependencies { implementation project(path: ':sdk') - implementation 'androidx.appcompat:appcompat:1.6.1' - implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1' - implementation 'com.google.android.material:material:1.8.0' + implementation(libs.androidx.appcompat) + implementation(libs.androidx.lifecycle) - implementation 'androidx.activity:activity-compose:1.7.0' - implementation "androidx.compose.ui:ui:$compose_ui_version" - implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version" - implementation 'androidx.compose.material:material:1.4.0' + implementation platform(libs.compose.bom) + implementation(libs.compose.activity) + implementation(libs.compose.ui) + implementation(libs.compose.tooling) + implementation(libs.compose.material) - implementation 'com.squareup.okhttp3:okhttp:4.10.0' + implementation(libs.okhttp.core) - debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version" - debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version" + debugImplementation(libs.compose.tooling) + debugImplementation(libs.compose.test.manifest) } diff --git a/dev-app/src/main/java/com/uid2/dev/network/AppUID2Client.kt b/dev-app/src/main/java/com/uid2/dev/network/AppUID2Client.kt index 95a96fe..1efa625 100644 --- a/dev-app/src/main/java/com/uid2/dev/network/AppUID2Client.kt +++ b/dev-app/src/main/java/com/uid2/dev/network/AppUID2Client.kt @@ -50,56 +50,54 @@ class AppUID2Client( * address, or telephone number. */ @Throws(AppUID2ClientException::class) - suspend fun generateIdentity( - requestString: String, - type: RequestType, - ): UID2Identity? = withContext(Dispatchers.IO) { - // Check to make sure we have a valid endpoint to hit. - val url = apiGenerateUrl ?: throw AppUID2ClientException(ERROR_UNKNOWN_API) - - // Check that the key and secret were provided. - if (key.isEmpty() || secret.isEmpty()) { - throw AppUID2ClientException(ERROR_NO_SECRET_OR_KEY) - } + suspend fun generateIdentity(requestString: String, type: RequestType): UID2Identity? = + withContext(Dispatchers.IO) { + // Check to make sure we have a valid endpoint to hit. + val url = apiGenerateUrl ?: throw AppUID2ClientException(ERROR_UNKNOWN_API) + + // Check that the key and secret were provided. + if (key.isEmpty() || secret.isEmpty()) { + throw AppUID2ClientException(ERROR_NO_SECRET_OR_KEY) + } - // The secret should be Base64 encoded. Let's decode it and verify that what we have appears valid. - val secretBytes = runCatching { Base64.decode(secret, Base64.DEFAULT) }.getOrNull() - ?: throw AppUID2ClientException(ERROR_UNABLE_TO_DECODE_SECRET) - - // The request will contain an encrypted payload which contains the verified identity of the user. - val requestBody = encryptRequest( - secretBytes, - mapOf(type.parameter to requestString), - ) ?: throw AppUID2ClientException(ERROR_UNABLE_TO_ENCRYPT_REQUEST) - - val request = Request.Builder() - .url(url) - .addHeader(REQUEST_HEADER_AUTHORIZATION, REQUEST_HEADER_BEARER + key) - .addHeader(REQUEST_HEADER_CONTENT_TYPE, REQUEST_HEADER_TEXT_PLAIN) - .post(requestBody.toRequestBody()) - .build() - - // Make the request and verify that it was successful. - val response = client.newCall(request).execute() - if (!response.isSuccessful) { - throw AppUID2ClientException(ERROR_REQUEST_FAILED + response.code) - } + // The secret should be Base64 encoded. Let's decode it and verify that what we have appears valid. + val secretBytes = runCatching { Base64.decode(secret, Base64.DEFAULT) }.getOrNull() + ?: throw AppUID2ClientException(ERROR_UNABLE_TO_DECODE_SECRET) + + // The request will contain an encrypted payload which contains the verified identity of the user. + val requestBody = encryptRequest( + secretBytes, + mapOf(type.parameter to requestString), + ) ?: throw AppUID2ClientException(ERROR_UNABLE_TO_ENCRYPT_REQUEST) + + val request = Request.Builder() + .url(url) + .addHeader(REQUEST_HEADER_AUTHORIZATION, REQUEST_HEADER_BEARER + key) + .addHeader(REQUEST_HEADER_CONTENT_TYPE, REQUEST_HEADER_TEXT_PLAIN) + .post(requestBody.toRequestBody()) + .build() + + // Make the request and verify that it was successful. + val response = client.newCall(request).execute() + if (!response.isSuccessful) { + throw AppUID2ClientException(ERROR_REQUEST_FAILED + response.code) + } - // If we have a valid response, we can try to decrypt it. - val responseBody = decryptResponse( - secret, - response.body?.string() - ?: throw AppUID2ClientException(ERROR_RESPONSE_NO_BODY), - ) ?: throw AppUID2ClientException(ERROR_UNABLE_TO_DECRYPT_RESPONSE) + // If we have a valid response, we can try to decrypt it. + val responseBody = decryptResponse( + secret, + response.body?.string() + ?: throw AppUID2ClientException(ERROR_RESPONSE_NO_BODY), + ) ?: throw AppUID2ClientException(ERROR_UNABLE_TO_DECRYPT_RESPONSE) - // Now try to parse the decrypted response (as JSON). - val responseToken = runCatching { - GenerateTokenResponse.fromJson(JSONObject(responseBody)) - }.getOrNull() ?: throw AppUID2ClientException(ERROR_UNABLE_TO_PARSE_RESPONSE) + // Now try to parse the decrypted response (as JSON). + val responseToken = runCatching { + GenerateTokenResponse.fromJson(JSONObject(responseBody)) + }.getOrNull() ?: throw AppUID2ClientException(ERROR_UNABLE_TO_PARSE_RESPONSE) - // After all that, we should finally have a valid UID2Identity! - return@withContext responseToken.body - } + // After all that, we should finally have a valid UID2Identity! + return@withContext responseToken.body + } private fun encryptRequest(key: ByteArray, params: Map): ByteArray? { // The body of the payload is expected to be the following: diff --git a/dev-app/src/main/java/com/uid2/dev/ui/views/EmailInputView.kt b/dev-app/src/main/java/com/uid2/dev/ui/views/EmailInputView.kt index f569e25..f1f7b22 100644 --- a/dev-app/src/main/java/com/uid2/dev/ui/views/EmailInputView.kt +++ b/dev-app/src/main/java/com/uid2/dev/ui/views/EmailInputView.kt @@ -10,7 +10,8 @@ import androidx.compose.material.MaterialTheme import androidx.compose.material.Text import androidx.compose.material.TextField import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.ArrowForward +import androidx.compose.material.icons.Icons.AutoMirrored.Filled +import androidx.compose.material.icons.automirrored.filled.ArrowForward import androidx.compose.material.icons.filled.Email import androidx.compose.runtime.Composable import androidx.compose.runtime.mutableStateOf @@ -50,7 +51,7 @@ fun EmailInputView(modifier: Modifier, onEmailEntered: (String) -> Unit) { backgroundColor = MaterialTheme.colors.primary, ) { Icon( - imageVector = Icons.Default.ArrowForward, + imageVector = Filled.ArrowForward, contentDescription = stringResource(R.string.email_submit_content_description), tint = Color.White, ) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..fc1aeaf --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,53 @@ +[versions] +agp = "8.3.2" +kotlin = "1.9.23" +core-ktx = "1.13.0" +junit = "4.13.2" +appcompat = "1.6.1" +coroutines-version = "1.8.0" +compose = "1.9.0" +compose-bom = "2024.04.01" +compose-tooling = "1.6.6" +gma = "23.0.0" +ima = "3.33.0" + +[libraries] +core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "core-ktx" } +kotlinx-coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version = "1.8.0" } +androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } +androidx-lifecycle = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-ktx", version = "2.7.0" } + +# Compose +compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "compose-bom" } +compose-activity = { group = "androidx.activity", name = "activity-compose", version.ref = "compose" } +compose-ui = { group = "androidx.compose.ui", name = "ui", version.ref = "compose-tooling" } +compose-tooling = { group = "androidx.compose.ui", name = "ui-tooling", version.ref = "compose-tooling" } +compose-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest", version.ref = "compose-tooling"} +compose-material = { group = "androidx.compose.material", name = "material", version = "1.6.6" } + +# OkHttp +okhttp-core = { group = "com.squareup.okhttp3", name = "okhttp", version = "4.12.0" } + +# GMA / IMA +gma-ads = { group = "com.google.android.gms", name = "play-services-ads", version.ref = "gma" } +ima-ads = { group = "com.google.ads.interactivemedia.v3", name = "interactivemedia", version.ref = "ima" } +androidx-multidex = { group = "androidx.multidex", name = "multidex", version = "2.0.1" } +androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version = "2.1.4" } +androidx-media = { group = "androidx.media", name = "media", version = "1.7.0" } +androidx-browser = { group = "androidx.browser", name = "browser", version = "1.8.0" } +androidx-activity-ktx = { group = "androidx.activity", name = "activity-ktx", version = "1.9.0" } + +# Testing +junit = { group = "junit", name = "junit", version.ref = "junit" } +kotlinx-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "coroutines-version" } +json = { group = "org.json", name = "json", version = "20240303" } +mockito-kotlin = { group = "org.mockito.kotlin", name = "mockito-kotlin", version = "4.1.0" } +mockito-inline = { group = "org.mockito", name = "mockito-inline", version = "4.8.0" } + +[plugins] +androidApplication = { id = "com.android.application", version.ref = "agp" } +androidLibrary = { id = "com.android.library", version.ref = "agp" } +kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } +spotless = { id = "com.diffplug.spotless", version = "6.25.0" } +dokka = { id = "org.jetbrains.dokka", version = "1.9.20" } +mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.28.0" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e708b1c..e644113 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index cacc95f..b82aa23 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ -#Mon Mar 13 14:21:49 GMT 2023 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip distributionPath=wrapper/dists -zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 4f906e0..1aa94a4 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,67 +17,99 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -87,9 +119,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,88 +130,120 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +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 +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index ac1b06f..7101f8e 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,13 +41,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -56,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/sdk/build.gradle b/sdk/build.gradle index f3c02fc..f222fae 100644 --- a/sdk/build.gradle +++ b/sdk/build.gradle @@ -1,8 +1,8 @@ plugins { - id 'com.android.library' - id 'org.jetbrains.kotlin.android' - id 'org.jetbrains.dokka' - id 'com.vanniktech.maven.publish' + alias libs.plugins.androidLibrary + alias libs.plugins.kotlinAndroid + alias libs.plugins.dokka + alias libs.plugins.mavenPublish } apply from: rootProject.file("$rootDir/common.gradle") @@ -33,12 +33,10 @@ android { } dependencies { - testImplementation 'junit:junit:4.13.2' + testImplementation(libs.junit) - testImplementation 'org.mockito.kotlin:mockito-kotlin:4.1.0' - testImplementation 'org.mockito:mockito-inline:4.8.0' + testImplementation(libs.mockito.kotlin) + testImplementation(libs.mockito.inline) - testImplementation 'org.json:json:20180813' - - dokkaPlugin 'org.jetbrains.dokka:android-documentation-plugin:1.9.10' + testImplementation(libs.json) } diff --git a/sdk/src/main/java/com/uid2/UID2Client.kt b/sdk/src/main/java/com/uid2/UID2Client.kt index 4b626d7..530c1e7 100644 --- a/sdk/src/main/java/com/uid2/UID2Client.kt +++ b/sdk/src/main/java/com/uid2/UID2Client.kt @@ -46,48 +46,46 @@ internal class UID2Client( PayloadDecryptException::class, InvalidPayloadException::class, ) - suspend fun refreshIdentity( - refreshToken: String, - refreshResponseKey: String, - ): RefreshPackage = withContext(ioDispatcher) { - logger.i(TAG) { "Refreshing identity" } + suspend fun refreshIdentity(refreshToken: String, refreshResponseKey: String): RefreshPackage = + withContext(ioDispatcher) { + logger.i(TAG) { "Refreshing identity" } - // Check to make sure we have a valid endpoint to hit. - val url = apiRefreshUrl ?: run { - logger.e(TAG) { "Error determining identity refresh API" } - throw InvalidApiUrlException() - } + // Check to make sure we have a valid endpoint to hit. + val url = apiRefreshUrl ?: run { + logger.e(TAG) { "Error determining identity refresh API" } + throw InvalidApiUrlException() + } - // Build the request to refresh the token. - val request = NetworkRequest( - NetworkRequestType.POST, - mapOf( - "X-UID2-Client-Version" to clientVersion, - "Content-Type" to "application/x-www-form-urlencoded", - ), - refreshToken, - ) + // Build the request to refresh the token. + val request = NetworkRequest( + NetworkRequestType.POST, + mapOf( + "X-UID2-Client-Version" to clientVersion, + "Content-Type" to "application/x-www-form-urlencoded", + ), + refreshToken, + ) - // Attempt to make the request via the provided NetworkSession. - val response = session.loadData(url, request) - if (response.code != HttpURLConnection.HTTP_OK) { - logger.e(TAG) { "Client details failure: ${response.code}" } - throw RefreshTokenException(response.code) - } + // Attempt to make the request via the provided NetworkSession. + val response = session.loadData(url, request) + if (response.code != HttpURLConnection.HTTP_OK) { + logger.e(TAG) { "Client details failure: ${response.code}" } + throw RefreshTokenException(response.code) + } - // The response should be an encrypted payload. Let's attempt to decrypt it using the key we were provided. - val payload = DataEnvelope.decrypt(refreshResponseKey, response.data, true) ?: run { - logger.e(TAG) { "Error decrypting response from client details" } - throw PayloadDecryptException() - } + // The response should be an encrypted payload. Let's attempt to decrypt it using the key we were provided. + val payload = DataEnvelope.decrypt(refreshResponseKey, response.data, true) ?: run { + logger.e(TAG) { "Error decrypting response from client details" } + throw PayloadDecryptException() + } - // The decrypted payload should be JSON which we can parse. - val refreshResponse = RefreshResponse.fromJson(JSONObject(String(payload, Charsets.UTF_8))) - return@withContext refreshResponse?.toRefreshPackage() ?: run { - logger.e(TAG) { "Error parsing response from client details" } - throw InvalidPayloadException() + // The decrypted payload should be JSON which we can parse. + val refreshResponse = RefreshResponse.fromJson(JSONObject(String(payload, Charsets.UTF_8))) + return@withContext refreshResponse?.toRefreshPackage() ?: run { + logger.e(TAG) { "Error parsing response from client details" } + throw InvalidPayloadException() + } } - } private companion object { const val TAG = "UID2Client" diff --git a/securesignals-gma-dev-app/build.gradle b/securesignals-gma-dev-app/build.gradle index b551c30..8852cd3 100644 --- a/securesignals-gma-dev-app/build.gradle +++ b/securesignals-gma-dev-app/build.gradle @@ -1,6 +1,6 @@ plugins { - id 'com.android.application' - id 'org.jetbrains.kotlin.android' + alias libs.plugins.androidApplication + alias libs.plugins.kotlinAndroid } apply from: rootProject.file("$rootDir/common.gradle") @@ -29,11 +29,11 @@ android { } dependencies { + implementation project(path: ':sdk') implementation project(path: ':securesignals-gma') - compileOnly 'com.uid2:uid2-android-sdk:0.5.0' - compileOnly 'com.google.android.gms:play-services-ads:22.2.0' + implementation(libs.gma.ads) - implementation 'androidx.multidex:multidex:2.0.1' - implementation 'androidx.appcompat:appcompat:1.6.1' - implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + implementation(libs.androidx.multidex) + implementation(libs.androidx.appcompat) + implementation(libs.androidx.constraintlayout) } diff --git a/securesignals-gma-dev-app/src/main/java/com/uid2/dev/BannerActivity.java b/securesignals-gma-dev-app/src/main/java/com/uid2/dev/BannerActivity.java index 3b8de44..6a3d3e8 100644 --- a/securesignals-gma-dev-app/src/main/java/com/uid2/dev/BannerActivity.java +++ b/securesignals-gma-dev-app/src/main/java/com/uid2/dev/BannerActivity.java @@ -1,7 +1,5 @@ package com.uid2.dev; -import static com.google.ads.AdRequest.LOGTAG; - import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; import android.util.Log; @@ -105,7 +103,7 @@ private void loadUID2Identity() { fromJsonIdentity.getRefreshResponseKey()); UID2Manager.getInstance().setIdentity(identity); } catch (Exception e) { - Log.e(LOGTAG, "Error loading Identity: " + e); + Log.e(TAG, "Error loading Identity: " + e); } } diff --git a/securesignals-gma-dev-app/src/main/java/com/uid2/dev/GMADevApplication.java b/securesignals-gma-dev-app/src/main/java/com/uid2/dev/GMADevApplication.java index 4d3ed26..29587b6 100644 --- a/securesignals-gma-dev-app/src/main/java/com/uid2/dev/GMADevApplication.java +++ b/securesignals-gma-dev-app/src/main/java/com/uid2/dev/GMADevApplication.java @@ -1,6 +1,8 @@ package com.uid2.dev; import android.app.Application; +import android.util.Log; + import com.uid2.UID2Manager; public class GMADevApplication extends Application { @@ -8,7 +10,13 @@ public class GMADevApplication extends Application { @Override public void onCreate() { super.onCreate(); - UID2Manager.init(getApplicationContext()); - } + // Initialise the UID2Manager class. We will use it's DefaultNetworkSession rather than providing our own + // custom implementation. This can be done to allow wrapping something like OkHttp. + try { + UID2Manager.init(this.getApplicationContext()); + } catch (Exception ex) { + Log.e("IMADevApplication", "Error initialising UID2Manager", ex); + } + } } diff --git a/securesignals-gma/build.gradle b/securesignals-gma/build.gradle index 3b92ebd..5d987a2 100644 --- a/securesignals-gma/build.gradle +++ b/securesignals-gma/build.gradle @@ -1,7 +1,7 @@ plugins { - id 'com.android.library' - id 'org.jetbrains.kotlin.android' - id 'com.vanniktech.maven.publish' + alias libs.plugins.androidLibrary + alias libs.plugins.kotlinAndroid + alias libs.plugins.mavenPublish } apply from: rootProject.file("$rootDir/common.gradle") @@ -26,8 +26,7 @@ android { dependencies { implementation project(':sdk') - implementation 'com.google.android.gms:play-services-ads:22.2.0' + api(libs.gma.ads) - testImplementation 'junit:junit:4.13.2' - testImplementation 'com.google.android.gms:play-services-ads:22.2.0' + testImplementation(libs.junit) } diff --git a/securesignals-ima-dev-app/build.gradle b/securesignals-ima-dev-app/build.gradle index 47c59de..630e47c 100644 --- a/securesignals-ima-dev-app/build.gradle +++ b/securesignals-ima-dev-app/build.gradle @@ -1,6 +1,6 @@ plugins { - id 'com.android.application' - id 'org.jetbrains.kotlin.android' + alias libs.plugins.androidApplication + alias libs.plugins.kotlinAndroid } apply from: rootProject.file("$rootDir/common.gradle") @@ -29,18 +29,16 @@ android { } dependencies { + implementation project(path: ':sdk') implementation project(path: ':securesignals-ima') - compileOnly 'com.uid2:uid2-android-sdk:0.5.0' - compileOnly 'com.google.ads.interactivemedia.v3:interactivemedia:3.30.3' - - implementation 'androidx.core:core-ktx:1.10.0' - implementation 'androidx.appcompat:appcompat:1.6.1' - implementation 'androidx.activity:activity-ktx:1.7.0' - implementation 'com.google.android.material:material:1.8.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.4' - - implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0")) - implementation 'androidx.multidex:multidex:2.0.1' - implementation 'androidx.browser:browser:1.4.0' - implementation 'androidx.media:media:1.6.0' + implementation(libs.ima.ads) + + implementation(libs.core.ktx) + implementation(libs.androidx.appcompat) + implementation(libs.androidx.activity.ktx) + implementation(libs.androidx.constraintlayout) + + implementation(libs.androidx.multidex) + implementation(libs.androidx.browser) + implementation(libs.androidx.media) } diff --git a/securesignals-ima-dev-app/src/main/java/com/uid2/dev/IMADevApplication.java b/securesignals-ima-dev-app/src/main/java/com/uid2/dev/IMADevApplication.java index 2753915..d872cb5 100644 --- a/securesignals-ima-dev-app/src/main/java/com/uid2/dev/IMADevApplication.java +++ b/securesignals-ima-dev-app/src/main/java/com/uid2/dev/IMADevApplication.java @@ -1,6 +1,7 @@ package com.uid2.dev; import android.app.Application; +import android.util.Log; import com.uid2.UID2Manager; @@ -12,7 +13,10 @@ public void onCreate() { // Initialise the UID2Manager class. We will use it's DefaultNetworkSession rather than providing our own // custom implementation. This can be done to allow wrapping something like OkHttp. - UID2Manager.init(this.getApplicationContext()); + try { + UID2Manager.init(this.getApplicationContext()); + } catch (Exception ex) { + Log.e("IMADevApplication", "Error initialising UID2Manager", ex); + } } - } diff --git a/securesignals-ima/build.gradle b/securesignals-ima/build.gradle index 5832109..1d64e96 100644 --- a/securesignals-ima/build.gradle +++ b/securesignals-ima/build.gradle @@ -1,7 +1,7 @@ plugins { - id 'com.android.library' - id 'org.jetbrains.kotlin.android' - id 'com.vanniktech.maven.publish' + alias libs.plugins.androidLibrary + alias libs.plugins.kotlinAndroid + alias libs.plugins.mavenPublish } apply from: rootProject.file("$rootDir/common.gradle") @@ -26,8 +26,7 @@ android { dependencies { implementation project(path: ':sdk') - implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.30.3' + api(libs.ima.ads) - testImplementation 'junit:junit:4.13.2' - testImplementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.30.3' + testImplementation(libs.junit) }