Renaming APG to OpenPGP Keychain
This commit is contained in:
23
OpenPGP-Keychain-API-Demo/.gitignore
vendored
Normal file
23
OpenPGP-Keychain-API-Demo/.gitignore
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
#Android generated
|
||||
bin
|
||||
gen
|
||||
obj
|
||||
libs/armeabi
|
||||
lint.xml
|
||||
local.properties
|
||||
|
||||
#Eclipse
|
||||
.project
|
||||
.classpath
|
||||
.settings
|
||||
|
||||
#IntelliJ IDEA
|
||||
.idea
|
||||
*.iml
|
||||
|
||||
#Maven
|
||||
target
|
||||
release.properties
|
||||
|
||||
#Mac
|
||||
.DS_Store
|
||||
44
OpenPGP-Keychain-API-Demo/AndroidManifest.xml
Normal file
44
OpenPGP-Keychain-API-Demo/AndroidManifest.xml
Normal file
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.sufficientlysecure.keychain.demo"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" >
|
||||
|
||||
<uses-permission android:name="org.sufficientlysecure.keychain.permission.ACCESS_API" />
|
||||
<uses-permission android:name="org.sufficientlysecure.keychain.permission.ACCESS_KEYS" />
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="7"
|
||||
android:targetSdkVersion="14" />
|
||||
|
||||
<application
|
||||
android:icon="@drawable/icon"
|
||||
android:label="APG API Demo" >
|
||||
<activity
|
||||
android:name=".BaseActivity"
|
||||
android:label="APG API Demo" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".IntentDemoActivity"
|
||||
android:label="Intent Demo 1"
|
||||
android:windowSoftInputMode="stateHidden" />
|
||||
<activity
|
||||
android:name=".AidlDemoActivity"
|
||||
android:label="Aidl Demo (ACCESS_API permission)"
|
||||
android:windowSoftInputMode="stateHidden" />
|
||||
<activity
|
||||
android:name=".AidlDemoActivity2"
|
||||
android:label="Aidl Demo (ACCESS_KEYS permission)"
|
||||
android:windowSoftInputMode="stateHidden" />
|
||||
<activity
|
||||
android:name=".ContentProviderDemoActivity"
|
||||
android:label="Content Provider Demo"
|
||||
android:windowSoftInputMode="stateHidden" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
83
OpenPGP-Keychain-API-Demo/build.xml
Normal file
83
OpenPGP-Keychain-API-Demo/build.xml
Normal file
@@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="APG Integration Demo" default="help">
|
||||
|
||||
<!-- The local.properties file is created and updated by the 'android' tool.
|
||||
It contains the path to the SDK. It should *NOT* be checked into
|
||||
Version Control Systems. -->
|
||||
<property file="local.properties" />
|
||||
|
||||
<!-- The ant.properties file can be created by you. It is only edited by the
|
||||
'android' tool to add properties to it.
|
||||
This is the place to change some Ant specific build properties.
|
||||
Here are some properties you may want to change/update:
|
||||
|
||||
source.dir
|
||||
The name of the source directory. Default is 'src'.
|
||||
out.dir
|
||||
The name of the output directory. Default is 'bin'.
|
||||
|
||||
For other overridable properties, look at the beginning of the rules
|
||||
files in the SDK, at tools/ant/build.xml
|
||||
|
||||
Properties related to the SDK location or the project target should
|
||||
be updated using the 'android' tool with the 'update' action.
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems.
|
||||
|
||||
-->
|
||||
<property file="ant.properties" />
|
||||
|
||||
<!-- The project.properties file is created and updated by the 'android'
|
||||
tool, as well as ADT.
|
||||
|
||||
This contains project specific properties such as project target, and library
|
||||
dependencies. Lower level build properties are stored in ant.properties
|
||||
(or in .classpath for Eclipse projects).
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems. -->
|
||||
<loadproperties srcFile="project.properties" />
|
||||
|
||||
<!-- quick check on sdk.dir -->
|
||||
<fail
|
||||
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
|
||||
unless="sdk.dir"
|
||||
/>
|
||||
|
||||
<!--
|
||||
Import per project custom build rules if present at the root of the project.
|
||||
This is the place to put custom intermediary targets such as:
|
||||
-pre-build
|
||||
-pre-compile
|
||||
-post-compile (This is typically used for code obfuscation.
|
||||
Compiled code location: ${out.classes.absolute.dir}
|
||||
If this is not done in place, override ${out.dex.input.absolute.dir})
|
||||
-post-package
|
||||
-post-build
|
||||
-pre-clean
|
||||
-->
|
||||
<import file="custom_rules.xml" optional="true" />
|
||||
|
||||
<!-- Import the actual build file.
|
||||
|
||||
To customize existing targets, there are two options:
|
||||
- Customize only one target:
|
||||
- copy/paste the target into this file, *before* the
|
||||
<import> task.
|
||||
- customize it to your needs.
|
||||
- Customize the whole content of build.xml
|
||||
- copy/paste the content of the rules files (minus the top node)
|
||||
into this file, replacing the <import> task.
|
||||
- customize to your needs.
|
||||
|
||||
***********************
|
||||
****** IMPORTANT ******
|
||||
***********************
|
||||
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
|
||||
in order to avoid having your file be overridden by tools such as "android update project"
|
||||
-->
|
||||
<!-- version-tag: 1 -->
|
||||
<import file="${sdk.dir}/tools/ant/build.xml" />
|
||||
|
||||
</project>
|
||||
20
OpenPGP-Keychain-API-Demo/proguard-project.txt
Normal file
20
OpenPGP-Keychain-API-Demo/proguard-project.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
# To enable ProGuard in your project, edit project.properties
|
||||
# to define the proguard.config property as described in that file.
|
||||
#
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in ${sdk.dir}/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the ProGuard
|
||||
# include property in project.properties.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# 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 *;
|
||||
#}
|
||||
12
OpenPGP-Keychain-API-Demo/project.properties
Normal file
12
OpenPGP-Keychain-API-Demo/project.properties
Normal file
@@ -0,0 +1,12 @@
|
||||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system use,
|
||||
# "ant.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
|
||||
# Project target.
|
||||
target=android-15
|
||||
android.library.reference.1=../OpenPGP-Keychain-API-Lib
|
||||
BIN
OpenPGP-Keychain-API-Demo/res/drawable-hdpi/icon.png
Normal file
BIN
OpenPGP-Keychain-API-Demo/res/drawable-hdpi/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.2 KiB |
BIN
OpenPGP-Keychain-API-Demo/res/drawable-ldpi/icon.png
Normal file
BIN
OpenPGP-Keychain-API-Demo/res/drawable-ldpi/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.0 KiB |
BIN
OpenPGP-Keychain-API-Demo/res/drawable-mdpi/icon.png
Normal file
BIN
OpenPGP-Keychain-API-Demo/res/drawable-mdpi/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
BIN
OpenPGP-Keychain-API-Demo/res/drawable-xhdpi/icon.png
Normal file
BIN
OpenPGP-Keychain-API-Demo/res/drawable-xhdpi/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.0 KiB |
72
OpenPGP-Keychain-API-Demo/res/layout/aidl_demo.xml
Normal file
72
OpenPGP-Keychain-API-Demo/res/layout/aidl_demo.xml
Normal file
@@ -0,0 +1,72 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/aidl_demo_create_new_key"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="createNewKeyOnClick"
|
||||
android:text="Create new key" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/aidl_demo_select_secret_key"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="selectSecretKeyOnClick"
|
||||
android:text="Select secret key" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/aidl_demo_select_encryption_key"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="selectEncryptionKeysOnClick"
|
||||
android:text="Select encryption key(s)" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/aidl_demo_message"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="150dip"
|
||||
android:text="message"
|
||||
android:textAppearance="@android:style/TextAppearance.Small" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/aidl_demo_ciphertext"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="150dip"
|
||||
android:text="ciphertext"
|
||||
android:textAppearance="@android:style/TextAppearance.Small" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/aidl_demo_encrypt"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="encryptOnClick"
|
||||
android:text="Encrypt" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/aidl_demo_decrypt"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="decryptOnClick"
|
||||
android:text="Decrypt" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="APG Data:" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/aidl_demo_data"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:minLines="10" />
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
40
OpenPGP-Keychain-API-Demo/res/layout/aidl_demo2.xml
Normal file
40
OpenPGP-Keychain-API-Demo/res/layout/aidl_demo2.xml
Normal file
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/aidl_demo_select_encryption_key"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="selectEncryptionKeysOnClick"
|
||||
android:text="Select encryption key(s)" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/aidl_demo_keyrings"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="keyrings output"
|
||||
android:textAppearance="@android:style/TextAppearance.Small" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/aidl_demo_get_keyrings_strings"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="getKeyringsStringsOnClick"
|
||||
android:text="getKeyrings as Strings" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/aidl_demo_get_keyrings_bytes"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="getKeyringsBytesOnClick"
|
||||
android:text="getKeyringsBytes" />
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/content_provider_test1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="test1OnClick"
|
||||
android:text="Test 1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/content_provider_test2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="test2OnClick"
|
||||
android:text="Test 2" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/content_provider_output"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="150dip"
|
||||
android:text="output"
|
||||
android:textAppearance="@android:style/TextAppearance.Small" />
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
93
OpenPGP-Keychain-API-Demo/res/layout/intent_demo.xml
Normal file
93
OpenPGP-Keychain-API-Demo/res/layout/intent_demo.xml
Normal file
@@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/Button02"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="encryptOnClick"
|
||||
android:text="Encrypt" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/intent_demo_create_new_key"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="createNewKeyOnClick"
|
||||
android:text="Create new key" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/intent_demo_select_secret_key"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="selectSecretKeyOnClick"
|
||||
android:text="Select secret key" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/intent_demo_select_encryption_key"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="selectEncryptionKeysOnClick"
|
||||
android:text="Select encryption key(s)" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/intent_demo_message"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="150dip"
|
||||
android:text="message"
|
||||
android:textAppearance="@android:style/TextAppearance.Small" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/intent_demo_ciphertext"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="150dip"
|
||||
android:text="ciphertext"
|
||||
android:textAppearance="@android:style/TextAppearance.Small" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/intent_demo_encrypt"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="encryptOnClick"
|
||||
android:text="Encrypt" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/intent_demo_encrypt"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="encryptAndReturnOnClick"
|
||||
android:text="Encrypt and return result" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/intent_demo_decrypt"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="decryptOnClick"
|
||||
android:text="Decrypt" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/intent_demo_decrypt"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="decryptAndReturnOnClick"
|
||||
android:text="Decrypt and return result" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="APG Data:" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/intent_demo_data"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:minLines="10" />
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
23
OpenPGP-Keychain-API-Demo/res/xml/base_preference.xml
Normal file
23
OpenPGP-Keychain-API-Demo/res/xml/base_preference.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<PreferenceCategory android:title="Intent" >
|
||||
<Preference
|
||||
android:key="intent_demo"
|
||||
android:title="Intent Demo" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="Content Provider" >
|
||||
<Preference
|
||||
android:key="content_provider_demo"
|
||||
android:title="Content Provider Demo" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="AIDL" >
|
||||
<Preference
|
||||
android:key="aidl_demo"
|
||||
android:title="AIDL Demo (ACCESS_API permission)" />
|
||||
<Preference
|
||||
android:key="aidl_demo2"
|
||||
android:title="AIDL Demo (ACCESS_KEYS permission)" />
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
* Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
*
|
||||
* 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 org.sufficientlysecure.keychain.demo;
|
||||
|
||||
import org.sufficientlysecure.keychain.demo.R;
|
||||
import org.sufficientlysecure.keychain.integration.KeychainData;
|
||||
import org.sufficientlysecure.keychain.integration.KeychainIntentHelper;
|
||||
import org.sufficientlysecure.keychain.service.IKeychainApiService;
|
||||
import org.sufficientlysecure.keychain.service.IKeychainKeyService;
|
||||
import org.sufficientlysecure.keychain.service.handler.IKeychainDecryptHandler;
|
||||
import org.sufficientlysecure.keychain.service.handler.IKeychainEncryptHandler;
|
||||
import org.sufficientlysecure.keychain.service.handler.IKeychainGetDecryptionKeyIdHandler;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class AidlDemoActivity extends Activity {
|
||||
Activity mActivity;
|
||||
|
||||
TextView mMessageTextView;
|
||||
TextView mCiphertextTextView;
|
||||
TextView mDataTextView;
|
||||
|
||||
KeychainIntentHelper mKeychainIntentHelper;
|
||||
KeychainData mKeychainData;
|
||||
|
||||
private IKeychainApiService service = null;
|
||||
private ServiceConnection svcConn = new ServiceConnection() {
|
||||
public void onServiceConnected(ComponentName className, IBinder binder) {
|
||||
service = IKeychainApiService.Stub.asInterface(binder);
|
||||
}
|
||||
|
||||
public void onServiceDisconnected(ComponentName className) {
|
||||
service = null;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
setContentView(R.layout.aidl_demo);
|
||||
|
||||
mActivity = this;
|
||||
|
||||
mMessageTextView = (TextView) findViewById(R.id.aidl_demo_message);
|
||||
mCiphertextTextView = (TextView) findViewById(R.id.aidl_demo_ciphertext);
|
||||
mDataTextView = (TextView) findViewById(R.id.aidl_demo_data);
|
||||
|
||||
mKeychainIntentHelper = new KeychainIntentHelper(mActivity);
|
||||
mKeychainData = new KeychainData();
|
||||
|
||||
bindService(new Intent(IKeychainApiService.class.getName()), svcConn,
|
||||
Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
public void encryptOnClick(View view) {
|
||||
byte[] inputBytes = mMessageTextView.getText().toString().getBytes();
|
||||
|
||||
try {
|
||||
service.encryptAsymmetric(inputBytes, null, true, 0, mKeychainData.getPublicKeys(), 7,
|
||||
encryptHandler);
|
||||
} catch (RemoteException e) {
|
||||
exceptionImplementation(-1, e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void decryptOnClick(View view) {
|
||||
byte[] inputBytes = mCiphertextTextView.getText().toString().getBytes();
|
||||
|
||||
try {
|
||||
service.decryptAndVerifyAsymmetric(inputBytes, null, null, decryptHandler);
|
||||
} catch (RemoteException e) {
|
||||
exceptionImplementation(-1, e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private void updateView() {
|
||||
if (mKeychainData.getDecryptedData() != null) {
|
||||
mMessageTextView.setText(mKeychainData.getDecryptedData());
|
||||
}
|
||||
if (mKeychainData.getEncryptedData() != null) {
|
||||
mCiphertextTextView.setText(mKeychainData.getEncryptedData());
|
||||
}
|
||||
mDataTextView.setText(mKeychainData.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
unbindService(svcConn);
|
||||
}
|
||||
|
||||
private void exceptionImplementation(int exceptionId, String error) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle("Exception!").setMessage(error).setPositiveButton("OK", null).show();
|
||||
}
|
||||
|
||||
private final IKeychainEncryptHandler.Stub encryptHandler = new IKeychainEncryptHandler.Stub() {
|
||||
|
||||
@Override
|
||||
public void onException(final int exceptionId, final String message) throws RemoteException {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
exceptionImplementation(exceptionId, message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(final byte[] outputBytes, String outputUri) throws RemoteException {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
mKeychainData.setEncryptedData(new String(outputBytes));
|
||||
updateView();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private final IKeychainDecryptHandler.Stub decryptHandler = new IKeychainDecryptHandler.Stub() {
|
||||
|
||||
@Override
|
||||
public void onException(final int exceptionId, final String message) throws RemoteException {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
exceptionImplementation(exceptionId, message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(final byte[] outputBytes, String outputUri, boolean signature,
|
||||
long signatureKeyId, String signatureUserId, boolean signatureSuccess,
|
||||
boolean signatureUnknown) throws RemoteException {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
mKeychainData.setDecryptedData(new String(outputBytes));
|
||||
updateView();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private final IKeychainGetDecryptionKeyIdHandler.Stub helperHandler = new IKeychainGetDecryptionKeyIdHandler.Stub() {
|
||||
|
||||
@Override
|
||||
public void onException(final int exceptionId, final String message) throws RemoteException {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
exceptionImplementation(exceptionId, message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(long arg0, boolean arg1) throws RemoteException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Selection is done with Intents, not AIDL!
|
||||
*
|
||||
* @param view
|
||||
*/
|
||||
public void selectSecretKeyOnClick(View view) {
|
||||
mKeychainIntentHelper.selectSecretKey();
|
||||
}
|
||||
|
||||
public void selectEncryptionKeysOnClick(View view) {
|
||||
mKeychainIntentHelper.selectPublicKeys("user@example.com");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
// this updates the mKeychainData object to the result of the methods
|
||||
boolean result = mKeychainIntentHelper.onActivityResult(requestCode, resultCode, data,
|
||||
mKeychainData);
|
||||
if (result) {
|
||||
updateView();
|
||||
}
|
||||
|
||||
// continue with other activity results
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
*
|
||||
* 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 org.sufficientlysecure.keychain.demo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.sufficientlysecure.keychain.demo.R;
|
||||
import org.sufficientlysecure.keychain.integration.KeychainData;
|
||||
import org.sufficientlysecure.keychain.integration.KeychainIntentHelper;
|
||||
import org.sufficientlysecure.keychain.service.IKeychainKeyService;
|
||||
import org.sufficientlysecure.keychain.service.handler.IKeychainGetKeyringsHandler;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Base64;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class AidlDemoActivity2 extends Activity {
|
||||
Activity mActivity;
|
||||
|
||||
TextView mKeyringsTextView;
|
||||
|
||||
KeychainIntentHelper mKeychainIntentHelper;
|
||||
KeychainData mKeychainData;
|
||||
|
||||
byte[] keysBytes;
|
||||
ArrayList<String> keysStrings;
|
||||
|
||||
private IKeychainKeyService service = null;
|
||||
private ServiceConnection svcConn = new ServiceConnection() {
|
||||
public void onServiceConnected(ComponentName className, IBinder binder) {
|
||||
service = IKeychainKeyService.Stub.asInterface(binder);
|
||||
}
|
||||
|
||||
public void onServiceDisconnected(ComponentName className) {
|
||||
service = null;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
setContentView(R.layout.aidl_demo2);
|
||||
|
||||
mActivity = this;
|
||||
|
||||
mKeyringsTextView = (TextView) findViewById(R.id.aidl_demo_keyrings);
|
||||
|
||||
mKeychainIntentHelper = new KeychainIntentHelper(mActivity);
|
||||
mKeychainData = new KeychainData();
|
||||
|
||||
bindService(new Intent(IKeychainKeyService.class.getName()), svcConn,
|
||||
Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
public void getKeyringsStringsOnClick(View view) {
|
||||
try {
|
||||
service.getPublicKeyRings(mKeychainData.getPublicKeys(), true, getKeyringsHandler);
|
||||
} catch (RemoteException e) {
|
||||
exceptionImplementation(-1, e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void getKeyringsBytesOnClick(View view) {
|
||||
try {
|
||||
service.getPublicKeyRings(mKeychainData.getPublicKeys(), false, getKeyringsHandler);
|
||||
} catch (RemoteException e) {
|
||||
exceptionImplementation(-1, e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
private void updateView() {
|
||||
if (keysBytes != null) {
|
||||
mKeyringsTextView.setText(Base64.encodeToString(keysBytes, Base64.DEFAULT));
|
||||
} else if (keysStrings != null) {
|
||||
mKeyringsTextView.setText("");
|
||||
for (String output : keysStrings) {
|
||||
mKeyringsTextView.append(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
unbindService(svcConn);
|
||||
}
|
||||
|
||||
private void exceptionImplementation(int exceptionId, String error) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle("Exception!").setMessage(error).setPositiveButton("OK", null).show();
|
||||
}
|
||||
|
||||
private final IKeychainGetKeyringsHandler.Stub getKeyringsHandler = new IKeychainGetKeyringsHandler.Stub() {
|
||||
|
||||
@Override
|
||||
public void onException(final int exceptionId, final String message) throws RemoteException {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
exceptionImplementation(exceptionId, message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(final byte[] outputBytes, final List<String> outputStrings)
|
||||
throws RemoteException {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
if (outputBytes != null) {
|
||||
keysBytes = outputBytes;
|
||||
keysStrings = null;
|
||||
} else if (outputStrings != null) {
|
||||
keysBytes = null;
|
||||
keysStrings = (ArrayList<String>) outputStrings;
|
||||
}
|
||||
updateView();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public void selectEncryptionKeysOnClick(View view) {
|
||||
mKeychainIntentHelper.selectPublicKeys("user@example.com");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
// this updates the mKeychainData object to the result of the methods
|
||||
boolean result = mKeychainIntentHelper.onActivityResult(requestCode, resultCode, data,
|
||||
mKeychainData);
|
||||
if (result) {
|
||||
updateView();
|
||||
}
|
||||
|
||||
// continue with other activity results
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
*
|
||||
* 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 org.sufficientlysecure.keychain.demo;
|
||||
|
||||
import org.sufficientlysecure.keychain.demo.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceClickListener;
|
||||
import android.preference.PreferenceActivity;
|
||||
|
||||
public class BaseActivity extends PreferenceActivity {
|
||||
private Activity mActivity;
|
||||
|
||||
private Preference mIntentDemo;
|
||||
private Preference mContentProviderDemo;
|
||||
private Preference mAidlDemo;
|
||||
private Preference mAidlDemo2;
|
||||
|
||||
/**
|
||||
* Called when the activity is first created.
|
||||
*/
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mActivity = this;
|
||||
|
||||
// load preferences from xml
|
||||
addPreferencesFromResource(R.xml.base_preference);
|
||||
|
||||
// find preferences
|
||||
mIntentDemo = (Preference) findPreference("intent_demo");
|
||||
mContentProviderDemo = (Preference) findPreference("content_provider_demo");
|
||||
mAidlDemo = (Preference) findPreference("aidl_demo");
|
||||
mAidlDemo2 = (Preference) findPreference("aidl_demo2");
|
||||
|
||||
mIntentDemo.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
startActivity(new Intent(mActivity, IntentDemoActivity.class));
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
mContentProviderDemo.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
startActivity(new Intent(mActivity, ContentProviderDemoActivity.class));
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
mAidlDemo.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
startActivity(new Intent(mActivity, AidlDemoActivity.class));
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
mAidlDemo2.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
startActivity(new Intent(mActivity, AidlDemoActivity2.class));
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
*
|
||||
* 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 org.sufficientlysecure.keychain.demo;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.sufficientlysecure.keychain.demo.R;
|
||||
import org.sufficientlysecure.keychain.integration.KeychainContentProviderHelper;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class ContentProviderDemoActivity extends Activity {
|
||||
Activity mActivity;
|
||||
|
||||
TextView mOutputTextView;
|
||||
TextView mCiphertextTextView;
|
||||
TextView mDataTextView;
|
||||
|
||||
KeychainContentProviderHelper mKeychainContentProviderHelper;
|
||||
|
||||
/**
|
||||
* Instantiate View for this Activity
|
||||
*/
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.content_provider_demo);
|
||||
|
||||
mActivity = this;
|
||||
|
||||
mOutputTextView = (TextView) findViewById(R.id.content_provider_output);
|
||||
|
||||
mKeychainContentProviderHelper = new KeychainContentProviderHelper(mActivity);
|
||||
}
|
||||
|
||||
public void test1OnClick(View view) {
|
||||
long[] test = mKeychainContentProviderHelper.getPublicKeyringIdsByEmail("user@example.com");
|
||||
mOutputTextView.setText(Arrays.toString(test));
|
||||
}
|
||||
|
||||
public void test2OnClick(View view) {
|
||||
boolean test = mKeychainContentProviderHelper.hasPublicKeyringByEmail("user@example.com");
|
||||
if (test) {
|
||||
mOutputTextView.setText("true");
|
||||
} else {
|
||||
mOutputTextView.setText("false");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
*
|
||||
* 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 org.sufficientlysecure.keychain.demo;
|
||||
|
||||
import org.sufficientlysecure.keychain.demo.R;
|
||||
import org.sufficientlysecure.keychain.integration.KeychainData;
|
||||
import org.sufficientlysecure.keychain.integration.KeychainIntentHelper;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class IntentDemoActivity extends Activity {
|
||||
Activity mActivity;
|
||||
|
||||
TextView mMessageTextView;
|
||||
TextView mCiphertextTextView;
|
||||
TextView mDataTextView;
|
||||
|
||||
KeychainIntentHelper mKeychainIntentHelper;
|
||||
KeychainData mKeychainData;
|
||||
|
||||
/**
|
||||
* Instantiate View for this Activity
|
||||
*/
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.intent_demo);
|
||||
|
||||
mActivity = this;
|
||||
|
||||
mMessageTextView = (TextView) findViewById(R.id.intent_demo_message);
|
||||
mCiphertextTextView = (TextView) findViewById(R.id.intent_demo_ciphertext);
|
||||
mDataTextView = (TextView) findViewById(R.id.intent_demo_data);
|
||||
|
||||
mKeychainIntentHelper = new KeychainIntentHelper(mActivity);
|
||||
mKeychainData = new KeychainData();
|
||||
}
|
||||
|
||||
public void createNewKeyOnClick(View view) {
|
||||
// mKeychainIntentHelper.createNewKey();
|
||||
mKeychainIntentHelper.createNewKey("test <user@example.com>", true, true);
|
||||
}
|
||||
|
||||
public void selectSecretKeyOnClick(View view) {
|
||||
mKeychainIntentHelper.selectSecretKey();
|
||||
}
|
||||
|
||||
public void selectEncryptionKeysOnClick(View view) {
|
||||
mKeychainIntentHelper.selectPublicKeys("user@example.com");
|
||||
}
|
||||
|
||||
public void encryptOnClick(View view) {
|
||||
mKeychainIntentHelper.encrypt(mMessageTextView.getText().toString(),
|
||||
mKeychainData.getPublicKeys(), mKeychainData.getSecretKeyId(), false);
|
||||
}
|
||||
|
||||
public void encryptAndReturnOnClick(View view) {
|
||||
mKeychainIntentHelper.encrypt(mMessageTextView.getText().toString(),
|
||||
mKeychainData.getPublicKeys(), mKeychainData.getSecretKeyId(), true);
|
||||
}
|
||||
|
||||
public void decryptOnClick(View view) {
|
||||
mKeychainIntentHelper.decrypt(mCiphertextTextView.getText().toString(), false);
|
||||
}
|
||||
|
||||
public void decryptAndReturnOnClick(View view) {
|
||||
mKeychainIntentHelper.decrypt(mCiphertextTextView.getText().toString(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
// this updates the mKeychainData object to the result of the methods
|
||||
boolean result = mKeychainIntentHelper.onActivityResult(requestCode, resultCode, data,
|
||||
mKeychainData);
|
||||
if (result) {
|
||||
updateView();
|
||||
}
|
||||
|
||||
// continue with other activity results
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
private void updateView() {
|
||||
if (mKeychainData.getDecryptedData() != null) {
|
||||
mMessageTextView.setText(mKeychainData.getDecryptedData());
|
||||
}
|
||||
if (mKeychainData.getEncryptedData() != null) {
|
||||
mCiphertextTextView.setText(mKeychainData.getEncryptedData());
|
||||
}
|
||||
mDataTextView.setText(mKeychainData.toString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user