aboutsummaryrefslogtreecommitdiff
path: root/java_src/examples
diff options
context:
space:
mode:
authorambrosin <ambrosin@google.com>2022-10-11 00:33:43 -0700
committerCopybara-Service <copybara-worker@google.com>2022-10-11 00:34:51 -0700
commitdc94612251e3ea79e80c6ea05dcda3a54afe40ca (patch)
tree8e2711178a9b57abf07c7434ab76244413cb4aa8 /java_src/examples
parent136a3b653e10a9314da845dafd003a717c03d6fb (diff)
downloadtink-dc94612251e3ea79e80c6ea05dcda3a54afe40ca.tar.gz
Move Android example to Tink Java examples.
Also upgrade Gradle to v7.4 and AGP to 4.2.2, and use SDK version 29. PiperOrigin-RevId: 480274932
Diffstat (limited to 'java_src/examples')
-rw-r--r--java_src/examples/android/helloworld/README.md15
-rw-r--r--java_src/examples/android/helloworld/app/build.gradle48
-rw-r--r--java_src/examples/android/helloworld/app/maven_local.gradle3
-rw-r--r--java_src/examples/android/helloworld/app/maven_snapshot.gradle3
-rw-r--r--java_src/examples/android/helloworld/app/src/main/AndroidManifest.xml26
-rw-r--r--java_src/examples/android/helloworld/app/src/main/java/com/helloworld/MainActivity.java110
-rw-r--r--java_src/examples/android/helloworld/app/src/main/java/com/helloworld/TinkApplication.java56
-rw-r--r--java_src/examples/android/helloworld/app/src/main/res/layout/activity_main.xml106
-rw-r--r--java_src/examples/android/helloworld/app/src/main/res/mipmap-hdpi/ic_launcher.pngbin0 -> 3418 bytes
-rw-r--r--java_src/examples/android/helloworld/app/src/main/res/mipmap-hdpi/ic_launcher_round.pngbin0 -> 4208 bytes
-rw-r--r--java_src/examples/android/helloworld/app/src/main/res/mipmap-mdpi/ic_launcher.pngbin0 -> 2206 bytes
-rw-r--r--java_src/examples/android/helloworld/app/src/main/res/mipmap-mdpi/ic_launcher_round.pngbin0 -> 2555 bytes
-rw-r--r--java_src/examples/android/helloworld/app/src/main/res/mipmap-xhdpi/ic_launcher.pngbin0 -> 4842 bytes
-rw-r--r--java_src/examples/android/helloworld/app/src/main/res/mipmap-xhdpi/ic_launcher_round.pngbin0 -> 6114 bytes
-rw-r--r--java_src/examples/android/helloworld/app/src/main/res/mipmap-xxhdpi/ic_launcher.pngbin0 -> 7718 bytes
-rw-r--r--java_src/examples/android/helloworld/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.pngbin0 -> 10056 bytes
-rw-r--r--java_src/examples/android/helloworld/app/src/main/res/mipmap-xxxhdpi/ic_launcher.pngbin0 -> 10486 bytes
-rw-r--r--java_src/examples/android/helloworld/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.pngbin0 -> 14696 bytes
-rw-r--r--java_src/examples/android/helloworld/app/src/main/res/values/colors.xml6
-rw-r--r--java_src/examples/android/helloworld/app/src/main/res/values/dimens.xml5
-rw-r--r--java_src/examples/android/helloworld/app/src/main/res/values/strings.xml26
-rw-r--r--java_src/examples/android/helloworld/app/src/main/res/values/styles.xml11
-rw-r--r--java_src/examples/android/helloworld/build.gradle27
-rw-r--r--java_src/examples/android/helloworld/gradle.properties23
-rw-r--r--java_src/examples/android/helloworld/gradle/wrapper/gradle-wrapper.jarbin0 -> 59203 bytes
-rw-r--r--java_src/examples/android/helloworld/gradle/wrapper/gradle-wrapper.properties5
-rwxr-xr-xjava_src/examples/android/helloworld/gradlew185
-rwxr-xr-xjava_src/examples/android/helloworld/gradlew.bat89
-rw-r--r--java_src/examples/android/helloworld/settings.gradle1
29 files changed, 745 insertions, 0 deletions
diff --git a/java_src/examples/android/helloworld/README.md b/java_src/examples/android/helloworld/README.md
new file mode 100644
index 000000000..0d05c530e
--- /dev/null
+++ b/java_src/examples/android/helloworld/README.md
@@ -0,0 +1,15 @@
+# Android Hello World
+
+This is a simple app that allows encrypting and decrypting strings
+with keys stored in private shared preferences. On Android M or newer
+the keys are further encrypted with a master key stored in Android
+Keystore.
+
+It demonstrates the basic steps of using Tink, namely generating or
+loading key material, obtaining a primitive, and using the primitive
+to do crypto. It also shows how one can add a dependency on Tink
+using Gradle.
+
+The easiest way to build this app is to import it to Android Studio. You can
+also
+[build it from the command line](https://developer.android.com/studio/build/building-cmdline).
diff --git a/java_src/examples/android/helloworld/app/build.gradle b/java_src/examples/android/helloworld/app/build.gradle
new file mode 100644
index 000000000..82ad967b0
--- /dev/null
+++ b/java_src/examples/android/helloworld/app/build.gradle
@@ -0,0 +1,48 @@
+apply plugin: 'com.android.application'
+
+android {
+ compileSdkVersion 29
+ defaultConfig {
+ applicationId "com.helloworld"
+ minSdkVersion 23
+ targetSdkVersion 29
+ versionCode 1
+ versionName "1.0"
+ testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
+ }
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+ }
+ }
+ compileOptions {
+ sourceCompatibility 1.8
+ targetCompatibility 1.8
+ }
+ lintOptions {
+ abortOnError false
+ }
+}
+
+apply from: "maven_${mavenLocation}.gradle"
+
+dependencies {
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
+ androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
+ exclude group: 'com.android.support', module: 'support-annotations'
+ // This is already included in protobuf-lite that Tink depends on.
+ exclude group: 'com.google.code.findbugs'
+ })
+ implementation 'com.android.support:appcompat-v7:26.+'
+ implementation 'com.android.support:design:26.+'
+ testImplementation 'junit:junit:4.12'
+
+ // Tink HEAD-SNAPSHOT for Android.
+ // In production apps, please use a named version, e.g., 1.4.0.
+ implementation 'com.google.crypto.tink:tink-android:HEAD-SNAPSHOT'
+
+ // An artificial dependency to test whether Tink can co-exist with other
+ // protobuf dependencies. Please remove from production apps.
+ implementation 'com.google.protobuf:protobuf-lite:3.0.1'
+}
diff --git a/java_src/examples/android/helloworld/app/maven_local.gradle b/java_src/examples/android/helloworld/app/maven_local.gradle
new file mode 100644
index 000000000..72461d590
--- /dev/null
+++ b/java_src/examples/android/helloworld/app/maven_local.gradle
@@ -0,0 +1,3 @@
+repositories {
+ mavenLocal()
+}
diff --git a/java_src/examples/android/helloworld/app/maven_snapshot.gradle b/java_src/examples/android/helloworld/app/maven_snapshot.gradle
new file mode 100644
index 000000000..88a1df7cf
--- /dev/null
+++ b/java_src/examples/android/helloworld/app/maven_snapshot.gradle
@@ -0,0 +1,3 @@
+repositories {
+ maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
+}
diff --git a/java_src/examples/android/helloworld/app/src/main/AndroidManifest.xml b/java_src/examples/android/helloworld/app/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..0bb684815
--- /dev/null
+++ b/java_src/examples/android/helloworld/app/src/main/AndroidManifest.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.helloworld">
+
+ <!-- To auto-complete the email text field in the login form with the user's emails -->
+
+ <application
+ android:name=".TinkApplication"
+ android:allowBackup="true"
+ android:icon="@mipmap/ic_launcher"
+ android:label="@string/app_name"
+ android:roundIcon="@mipmap/ic_launcher_round"
+ android:supportsRtl="true"
+ android:theme="@style/AppTheme">
+ <activity
+ android:name=".MainActivity"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
diff --git a/java_src/examples/android/helloworld/app/src/main/java/com/helloworld/MainActivity.java b/java_src/examples/android/helloworld/app/src/main/java/com/helloworld/MainActivity.java
new file mode 100644
index 000000000..f32924fa4
--- /dev/null
+++ b/java_src/examples/android/helloworld/app/src/main/java/com/helloworld/MainActivity.java
@@ -0,0 +1,110 @@
+// Copyright 2017 Google Inc.
+//
+// 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.
+//
+////////////////////////////////////////////////////////////////////////////////
+
+package com.helloworld;
+
+import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
+import android.util.Base64;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.EditText;
+import com.google.protobuf.ByteString;
+import java.nio.charset.StandardCharsets;
+import java.security.GeneralSecurityException;
+
+/** This activity allows users to encrypt and decrypt a string. */
+public class MainActivity extends AppCompatActivity {
+ private TinkApplication mApplication;
+ private EditText mPlaintextView;
+ private EditText mAssociatedDataView;
+ private EditText mCiphertextView;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+
+ mApplication = (TinkApplication) getApplicationContext();
+
+ mPlaintextView = (EditText) findViewById(R.id.plaintext);
+ mAssociatedDataView = (EditText) findViewById(R.id.associated_data);
+ mCiphertextView = (EditText) findViewById(R.id.ciphertext);
+ Button mEncryptButton = (Button) findViewById(R.id.encrypt_button);
+ mEncryptButton.setOnClickListener(
+ new OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ attemptEncrypt();
+ }
+ });
+ Button mDecryptButton = (Button) findViewById(R.id.decrypt_button);
+ mDecryptButton.setOnClickListener(
+ new OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ attemptDecrypt();
+ }
+ });
+ }
+
+ private void attemptEncrypt() {
+ mPlaintextView.setError(null);
+ mCiphertextView.setError(null);
+ mCiphertextView.setText("");
+
+ try {
+ byte[] plaintext = mPlaintextView.getText().toString().getBytes(StandardCharsets.UTF_8);
+ // An artifical step to test whether Tink can co-exist with protobuf-lite.
+ ByteString pStr = ByteString.copyFrom(plaintext);
+ byte[] associatedData =
+ mAssociatedDataView.getText().toString().getBytes(StandardCharsets.UTF_8);
+ byte[] ciphertext = mApplication.aead.encrypt(pStr.toByteArray(), associatedData);
+ mCiphertextView.setText(base64Encode(ciphertext));
+ } catch (GeneralSecurityException | IllegalArgumentException e) {
+ mCiphertextView.setError(
+ String.format("%s: %s", getString(R.string.error_cannot_encrypt), e.toString()));
+ mPlaintextView.requestFocus();
+ }
+ }
+
+ private void attemptDecrypt() {
+ mPlaintextView.setError(null);
+ mPlaintextView.setText("");
+ mCiphertextView.setError(null);
+
+ try {
+ byte[] ciphertext = base64Decode(mCiphertextView.getText().toString());
+ byte[] associatedData =
+ mAssociatedDataView.getText().toString().getBytes(StandardCharsets.UTF_8);
+ byte[] plaintext = mApplication.aead.decrypt(ciphertext, associatedData);
+ mPlaintextView.setText(new String(plaintext, StandardCharsets.UTF_8));
+ } catch (GeneralSecurityException | IllegalArgumentException e) {
+ mPlaintextView.setError(
+ String.format("%s: %s", getString(R.string.error_cannot_decrypt), e.toString()));
+ mCiphertextView.requestFocus();
+ }
+ }
+
+ private static String base64Encode(final byte[] input) {
+ return Base64.encodeToString(input, Base64.DEFAULT);
+ }
+
+ private static byte[] base64Decode(String input) {
+ return Base64.decode(input, Base64.DEFAULT);
+ }
+}
diff --git a/java_src/examples/android/helloworld/app/src/main/java/com/helloworld/TinkApplication.java b/java_src/examples/android/helloworld/app/src/main/java/com/helloworld/TinkApplication.java
new file mode 100644
index 000000000..daefd700a
--- /dev/null
+++ b/java_src/examples/android/helloworld/app/src/main/java/com/helloworld/TinkApplication.java
@@ -0,0 +1,56 @@
+// Copyright 2017 Google Inc.
+//
+// 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.
+//
+////////////////////////////////////////////////////////////////////////////////
+
+package com.helloworld;
+
+import android.app.Application;
+import com.google.crypto.tink.Aead;
+import com.google.crypto.tink.Config;
+import com.google.crypto.tink.KeysetHandle;
+import com.google.crypto.tink.aead.AeadKeyTemplates;
+import com.google.crypto.tink.config.TinkConfig;
+import com.google.crypto.tink.integration.android.AndroidKeysetManager;
+import java.io.IOException;
+import java.security.GeneralSecurityException;
+
+/** A custom application that initializes the Tink runtime at application startup. */
+public class TinkApplication extends Application {
+ private static final String TAG = TinkApplication.class.toString();
+ private static final String PREF_FILE_NAME = "hello_world_pref";
+ private static final String TINK_KEYSET_NAME = "hello_world_keyset";
+ private static final String MASTER_KEY_URI = "android-keystore://hello_world_master_key";
+ public Aead aead;
+
+ @Override
+ public final void onCreate() {
+ super.onCreate();
+ try {
+ Config.register(TinkConfig.TINK_1_0_0);
+ aead = getOrGenerateNewKeysetHandle().getPrimitive(Aead.class);
+ } catch (GeneralSecurityException | IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private KeysetHandle getOrGenerateNewKeysetHandle() throws IOException, GeneralSecurityException {
+ return new AndroidKeysetManager.Builder()
+ .withSharedPref(getApplicationContext(), TINK_KEYSET_NAME, PREF_FILE_NAME)
+ .withKeyTemplate(AeadKeyTemplates.AES256_GCM)
+ .withMasterKeyUri(MASTER_KEY_URI)
+ .build()
+ .getKeysetHandle();
+ }
+}
diff --git a/java_src/examples/android/helloworld/app/src/main/res/layout/activity_main.xml b/java_src/examples/android/helloworld/app/src/main/res/layout/activity_main.xml
new file mode 100644
index 000000000..976ea2b67
--- /dev/null
+++ b/java_src/examples/android/helloworld/app/src/main/res/layout/activity_main.xml
@@ -0,0 +1,106 @@
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center_horizontal"
+ android:orientation="vertical"
+ android:paddingBottom="@dimen/activity_vertical_margin"
+ android:paddingLeft="@dimen/activity_horizontal_margin"
+ android:paddingRight="@dimen/activity_horizontal_margin"
+ android:paddingTop="@dimen/activity_vertical_margin"
+ tools:context="com.helloworld.MainActivity">
+
+ <ScrollView
+ android:id="@+id/login_form"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <LinearLayout
+ android:id="@+id/email_login_form"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <android.support.design.widget.TextInputLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:id="@+id/hint_plaintext"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:text="@string/hint_plaintext" />
+ <EditText
+ android:id="@+id/plaintext"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:hint="@string/prompt_plaintext"
+ android:inputType="textMultiLine"
+ android:lines="3"
+ android:minLines="3"
+ android:maxLines="10" />
+
+ </android.support.design.widget.TextInputLayout>
+
+ <android.support.design.widget.TextInputLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:id="@+id/hint_associated_data"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:text="@string/hint_associated_data" />
+
+ <EditText
+ android:id="@+id/associated_data"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:hint="@string/prompt_associated_data"
+ android:inputType="textMultiLine"
+ android:lines="3"
+ android:minLines="3"
+ android:maxLines="10" />
+
+ </android.support.design.widget.TextInputLayout>
+
+ <android.support.design.widget.TextInputLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:id="@+id/hint_ciphertext"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:text="@string/hint_ciphertext" />
+ <EditText
+ android:id="@+id/ciphertext"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:hint="@string/prompt_ciphertext"
+ android:inputType="textMultiLine"
+ android:lines="3"
+ android:minLines="3"
+ android:maxLines="10" />
+
+ </android.support.design.widget.TextInputLayout>
+
+ <Button
+ android:id="@+id/encrypt_button"
+ style="?android:textAppearanceSmall"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/action_encrypt"
+ android:textStyle="bold" />
+
+ <Button
+ android:id="@+id/decrypt_button"
+ style="?android:textAppearanceSmall"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/action_decrypt"
+ android:textStyle="bold" />
+
+ </LinearLayout>
+ </ScrollView>
+</LinearLayout>
diff --git a/java_src/examples/android/helloworld/app/src/main/res/mipmap-hdpi/ic_launcher.png b/java_src/examples/android/helloworld/app/src/main/res/mipmap-hdpi/ic_launcher.png
new file mode 100644
index 000000000..cde69bccc
--- /dev/null
+++ b/java_src/examples/android/helloworld/app/src/main/res/mipmap-hdpi/ic_launcher.png
Binary files differ
diff --git a/java_src/examples/android/helloworld/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/java_src/examples/android/helloworld/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
new file mode 100644
index 000000000..9a078e3e1
--- /dev/null
+++ b/java_src/examples/android/helloworld/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
Binary files differ
diff --git a/java_src/examples/android/helloworld/app/src/main/res/mipmap-mdpi/ic_launcher.png b/java_src/examples/android/helloworld/app/src/main/res/mipmap-mdpi/ic_launcher.png
new file mode 100644
index 000000000..c133a0cbd
--- /dev/null
+++ b/java_src/examples/android/helloworld/app/src/main/res/mipmap-mdpi/ic_launcher.png
Binary files differ
diff --git a/java_src/examples/android/helloworld/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/java_src/examples/android/helloworld/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
new file mode 100644
index 000000000..efc028a63
--- /dev/null
+++ b/java_src/examples/android/helloworld/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
Binary files differ
diff --git a/java_src/examples/android/helloworld/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/java_src/examples/android/helloworld/app/src/main/res/mipmap-xhdpi/ic_launcher.png
new file mode 100644
index 000000000..bfa42f0e7
--- /dev/null
+++ b/java_src/examples/android/helloworld/app/src/main/res/mipmap-xhdpi/ic_launcher.png
Binary files differ
diff --git a/java_src/examples/android/helloworld/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/java_src/examples/android/helloworld/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
new file mode 100644
index 000000000..3af2608a4
--- /dev/null
+++ b/java_src/examples/android/helloworld/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
Binary files differ
diff --git a/java_src/examples/android/helloworld/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/java_src/examples/android/helloworld/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
new file mode 100644
index 000000000..324e72cdd
--- /dev/null
+++ b/java_src/examples/android/helloworld/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/java_src/examples/android/helloworld/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/java_src/examples/android/helloworld/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
new file mode 100644
index 000000000..9bec2e623
--- /dev/null
+++ b/java_src/examples/android/helloworld/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
Binary files differ
diff --git a/java_src/examples/android/helloworld/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/java_src/examples/android/helloworld/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
new file mode 100644
index 000000000..aee44e138
--- /dev/null
+++ b/java_src/examples/android/helloworld/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Binary files differ
diff --git a/java_src/examples/android/helloworld/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/java_src/examples/android/helloworld/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
new file mode 100644
index 000000000..34947cd6b
--- /dev/null
+++ b/java_src/examples/android/helloworld/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
Binary files differ
diff --git a/java_src/examples/android/helloworld/app/src/main/res/values/colors.xml b/java_src/examples/android/helloworld/app/src/main/res/values/colors.xml
new file mode 100644
index 000000000..3ab3e9cbc
--- /dev/null
+++ b/java_src/examples/android/helloworld/app/src/main/res/values/colors.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <color name="colorPrimary">#3F51B5</color>
+ <color name="colorPrimaryDark">#303F9F</color>
+ <color name="colorAccent">#FF4081</color>
+</resources>
diff --git a/java_src/examples/android/helloworld/app/src/main/res/values/dimens.xml b/java_src/examples/android/helloworld/app/src/main/res/values/dimens.xml
new file mode 100644
index 000000000..47c822467
--- /dev/null
+++ b/java_src/examples/android/helloworld/app/src/main/res/values/dimens.xml
@@ -0,0 +1,5 @@
+<resources>
+ <!-- Default screen margins, per the Android Design guidelines. -->
+ <dimen name="activity_horizontal_margin">16dp</dimen>
+ <dimen name="activity_vertical_margin">16dp</dimen>
+</resources>
diff --git a/java_src/examples/android/helloworld/app/src/main/res/values/strings.xml b/java_src/examples/android/helloworld/app/src/main/res/values/strings.xml
new file mode 100644
index 000000000..6ddeaeb7f
--- /dev/null
+++ b/java_src/examples/android/helloworld/app/src/main/res/values/strings.xml
@@ -0,0 +1,26 @@
+<resources>
+ <string name="app_name">Tink Hello World</string>
+
+ <string name="prompt_plaintext">Message</string>
+ <string name="hint_plaintext">
+ The secrecy and integrity of this message will be guaranteed.
+ </string>
+
+ <string name="prompt_associated_data">Associated data</string>
+ <string name="hint_associated_data">
+ Only the integrity of this associated data will be guaranteed. For successful decryption it
+ must be the same as the associated data used during encryption.
+ </string>
+
+ <string name="prompt_ciphertext">Ciphertext</string>
+ <string name="hint_ciphertext">
+ The ciphertext is in Base64 encoding. Try to modify it and verify that the decryption will
+ fail.
+ </string>
+
+ <string name="action_encrypt">Encrypt</string>
+ <string name="action_decrypt">Decrypt</string>
+ <string name="error_cannot_encrypt">Cannot encrypt</string>
+ <string name="error_cannot_decrypt">Cannot decrypt</string>
+ <string name="error_field_required">This field is required</string>
+</resources>
diff --git a/java_src/examples/android/helloworld/app/src/main/res/values/styles.xml b/java_src/examples/android/helloworld/app/src/main/res/values/styles.xml
new file mode 100644
index 000000000..5885930df
--- /dev/null
+++ b/java_src/examples/android/helloworld/app/src/main/res/values/styles.xml
@@ -0,0 +1,11 @@
+<resources>
+
+ <!-- Base application theme. -->
+ <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
+ <!-- Customize your theme here. -->
+ <item name="colorPrimary">@color/colorPrimary</item>
+ <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
+ <item name="colorAccent">@color/colorAccent</item>
+ </style>
+
+</resources>
diff --git a/java_src/examples/android/helloworld/build.gradle b/java_src/examples/android/helloworld/build.gradle
new file mode 100644
index 000000000..775d2900d
--- /dev/null
+++ b/java_src/examples/android/helloworld/build.gradle
@@ -0,0 +1,27 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+
+buildscript {
+ repositories {
+ google()
+ mavenCentral()
+ }
+ dependencies {
+ // See AGP compatibility with Gradle here:
+ // https://developer.android.com/studio/releases/gradle-plugin#updating-gradle.
+ classpath 'com.android.tools.build:gradle:4.2.2'
+
+ // NOTE: Do not place your application dependencies here; they belong
+ // in the individual module build.gradle files
+ }
+}
+
+allprojects {
+ repositories {
+ google()
+ mavenCentral()
+ }
+}
+
+task clean(type: Delete) {
+ delete rootProject.buildDir
+}
diff --git a/java_src/examples/android/helloworld/gradle.properties b/java_src/examples/android/helloworld/gradle.properties
new file mode 100644
index 000000000..f874b2f75
--- /dev/null
+++ b/java_src/examples/android/helloworld/gradle.properties
@@ -0,0 +1,23 @@
+# Project-wide Gradle settings.
+
+# IDE (e.g. Android Studio) users:
+# Gradle settings configured through the IDE *will override*
+# any settings specified in this file.
+
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+org.gradle.jvmargs=-Xmx1536m
+
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
+
+# Preferred source for Maven packages:
+# "local": Local Maven repository (i.e. for testing without publishing)
+# "snapshot": Maven Central snapshot repository (i.e. for testing published
+# snapshots)
+mavenLocation=snapshot
diff --git a/java_src/examples/android/helloworld/gradle/wrapper/gradle-wrapper.jar b/java_src/examples/android/helloworld/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 000000000..e708b1c02
--- /dev/null
+++ b/java_src/examples/android/helloworld/gradle/wrapper/gradle-wrapper.jar
Binary files differ
diff --git a/java_src/examples/android/helloworld/gradle/wrapper/gradle-wrapper.properties b/java_src/examples/android/helloworld/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 000000000..41dfb8790
--- /dev/null
+++ b/java_src/examples/android/helloworld/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,5 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/java_src/examples/android/helloworld/gradlew b/java_src/examples/android/helloworld/gradlew
new file mode 100755
index 000000000..4f906e0c8
--- /dev/null
+++ b/java_src/examples/android/helloworld/gradlew
@@ -0,0 +1,185 @@
+#!/usr/bin/env sh
+
+#
+# Copyright 2015 the original author or authors.
+#
+# 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
+#
+# https://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.
+#
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# 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
+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"'
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn () {
+ echo "$*"
+}
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# 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
+ ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+
+# Determine the Java command to use to start the JVM.
+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"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+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.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+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
+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
+
+# 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
+ # 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\""
+ fi
+ i=`expr $i + 1`
+ 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"
+
+exec "$JAVACMD" "$@"
diff --git a/java_src/examples/android/helloworld/gradlew.bat b/java_src/examples/android/helloworld/gradlew.bat
new file mode 100755
index 000000000..ac1b06f93
--- /dev/null
+++ b/java_src/examples/android/helloworld/gradlew.bat
@@ -0,0 +1,89 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "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.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+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.
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="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
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/java_src/examples/android/helloworld/settings.gradle b/java_src/examples/android/helloworld/settings.gradle
new file mode 100644
index 000000000..e7b4def49
--- /dev/null
+++ b/java_src/examples/android/helloworld/settings.gradle
@@ -0,0 +1 @@
+include ':app'