AIDL API changes
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" >
|
||||
|
||||
<uses-permission android:name="org.thialfihar.android.apg.permission.READ_KEY_DATABASE" />
|
||||
<uses-permission android:name="org.thialfihar.android.apg.permission.ACCESS_API" />
|
||||
<uses-permission android:name="org.thialfihar.android.apg.permission.ACCESS_KEYS" />
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="7"
|
||||
@@ -29,7 +29,11 @@
|
||||
android:windowSoftInputMode="stateHidden" />
|
||||
<activity
|
||||
android:name=".AidlDemoActivity"
|
||||
android:label="Aidl Demo"
|
||||
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"
|
||||
|
||||
40
APG-API-Demo/res/layout/aidl_demo2.xml
Normal file
40
APG-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>
|
||||
@@ -6,15 +6,18 @@
|
||||
android:key="intent_demo"
|
||||
android:title="Intent Demo" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="AIDL" >
|
||||
<Preference
|
||||
android:key="aidl_demo"
|
||||
android:title="AIDL 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>
|
||||
@@ -18,9 +18,10 @@ package org.thialfihar.android.apg.demo;
|
||||
|
||||
import org.thialfihar.android.apg.integration.ApgData;
|
||||
import org.thialfihar.android.apg.integration.ApgIntentHelper;
|
||||
import org.thialfihar.android.apg.service.IApgEncryptDecryptHandler;
|
||||
import org.thialfihar.android.apg.service.IApgHelperHandler;
|
||||
import org.thialfihar.android.apg.service.IApgService;
|
||||
import org.thialfihar.android.apg.service.IApgApiService;
|
||||
import org.thialfihar.android.apg.service.handler.IApgDecryptHandler;
|
||||
import org.thialfihar.android.apg.service.handler.IApgEncryptHandler;
|
||||
import org.thialfihar.android.apg.service.handler.IApgGetDecryptionKeyIdHandler;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
@@ -44,10 +45,10 @@ public class AidlDemoActivity extends Activity {
|
||||
ApgIntentHelper mApgIntentHelper;
|
||||
ApgData mApgData;
|
||||
|
||||
private IApgService service = null;
|
||||
private IApgApiService service = null;
|
||||
private ServiceConnection svcConn = new ServiceConnection() {
|
||||
public void onServiceConnected(ComponentName className, IBinder binder) {
|
||||
service = IApgService.Stub.asInterface(binder);
|
||||
service = IApgApiService.Stub.asInterface(binder);
|
||||
}
|
||||
|
||||
public void onServiceDisconnected(ComponentName className) {
|
||||
@@ -69,7 +70,7 @@ public class AidlDemoActivity extends Activity {
|
||||
mApgIntentHelper = new ApgIntentHelper(mActivity);
|
||||
mApgData = new ApgData();
|
||||
|
||||
bindService(new Intent("org.thialfihar.android.apg.service.IApgService"), svcConn,
|
||||
bindService(new Intent("org.thialfihar.android.apg.service.IApgApiService"), svcConn,
|
||||
Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
@@ -77,8 +78,8 @@ public class AidlDemoActivity extends Activity {
|
||||
byte[] inputBytes = mMessageTextView.getText().toString().getBytes();
|
||||
|
||||
try {
|
||||
service.encryptAsymmetric(inputBytes, null, true, 0, mApgData.getEncryptionKeys(), 7,
|
||||
encryptDecryptHandler);
|
||||
service.encryptAsymmetric(inputBytes, null, true, 0, mApgData.getPublicKeys(), 7,
|
||||
encryptHandler);
|
||||
} catch (RemoteException e) {
|
||||
exceptionImplementation(-1, e.toString());
|
||||
}
|
||||
@@ -88,7 +89,7 @@ public class AidlDemoActivity extends Activity {
|
||||
byte[] inputBytes = mCiphertextTextView.getText().toString().getBytes();
|
||||
|
||||
try {
|
||||
service.decryptAndVerifyAsymmetric(inputBytes, null, null, encryptDecryptHandler);
|
||||
service.decryptAndVerifyAsymmetric(inputBytes, null, null, decryptHandler);
|
||||
} catch (RemoteException e) {
|
||||
exceptionImplementation(-1, e.toString());
|
||||
}
|
||||
@@ -116,7 +117,7 @@ public class AidlDemoActivity extends Activity {
|
||||
builder.setTitle("Exception!").setMessage(error).setPositiveButton("OK", null).show();
|
||||
}
|
||||
|
||||
private final IApgEncryptDecryptHandler.Stub encryptDecryptHandler = new IApgEncryptDecryptHandler.Stub() {
|
||||
private final IApgEncryptHandler.Stub encryptHandler = new IApgEncryptHandler.Stub() {
|
||||
|
||||
@Override
|
||||
public void onException(final int exceptionId, final String message) throws RemoteException {
|
||||
@@ -128,8 +129,7 @@ public class AidlDemoActivity extends Activity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccessEncrypt(final byte[] outputBytes, String outputUri)
|
||||
throws RemoteException {
|
||||
public void onSuccess(final byte[] outputBytes, String outputUri) throws RemoteException {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
mApgData.setEncryptedData(new String(outputBytes));
|
||||
@@ -138,8 +138,21 @@ public class AidlDemoActivity extends Activity {
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private final IApgDecryptHandler.Stub decryptHandler = new IApgDecryptHandler.Stub() {
|
||||
|
||||
@Override
|
||||
public void onSuccessDecrypt(final byte[] outputBytes, String outputUri, boolean signature,
|
||||
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() {
|
||||
@@ -153,7 +166,7 @@ public class AidlDemoActivity extends Activity {
|
||||
|
||||
};
|
||||
|
||||
private final IApgHelperHandler.Stub helperHandler = new IApgHelperHandler.Stub() {
|
||||
private final IApgGetDecryptionKeyIdHandler.Stub helperHandler = new IApgGetDecryptionKeyIdHandler.Stub() {
|
||||
|
||||
@Override
|
||||
public void onException(final int exceptionId, final String message) throws RemoteException {
|
||||
@@ -165,7 +178,7 @@ public class AidlDemoActivity extends Activity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccessGetDecryptionKey(long arg0, boolean arg1) throws RemoteException {
|
||||
public void onSuccess(long arg0, boolean arg1) throws RemoteException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
@@ -182,7 +195,7 @@ public class AidlDemoActivity extends Activity {
|
||||
}
|
||||
|
||||
public void selectEncryptionKeysOnClick(View view) {
|
||||
mApgIntentHelper.selectEncryptionKeys("user@example.com");
|
||||
mApgIntentHelper.selectPublicKeys("user@example.com");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* 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.thialfihar.android.apg.demo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.thialfihar.android.apg.integration.ApgData;
|
||||
import org.thialfihar.android.apg.integration.ApgIntentHelper;
|
||||
import org.thialfihar.android.apg.service.IApgKeyService;
|
||||
import org.thialfihar.android.apg.service.handler.IApgGetKeyringsHandler;
|
||||
|
||||
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;
|
||||
|
||||
ApgIntentHelper mApgIntentHelper;
|
||||
ApgData mApgData;
|
||||
|
||||
byte[] keysBytes;
|
||||
ArrayList<String> keysStrings;
|
||||
|
||||
private IApgKeyService service = null;
|
||||
private ServiceConnection svcConn = new ServiceConnection() {
|
||||
public void onServiceConnected(ComponentName className, IBinder binder) {
|
||||
service = IApgKeyService.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);
|
||||
|
||||
mApgIntentHelper = new ApgIntentHelper(mActivity);
|
||||
mApgData = new ApgData();
|
||||
|
||||
bindService(new Intent("org.thialfihar.android.apg.service.IApgKeyService"), svcConn,
|
||||
Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
public void getKeyringsStringsOnClick(View view) {
|
||||
try {
|
||||
service.getPublicKeyRings(mApgData.getPublicKeys(), true, getKeyringsHandler);
|
||||
} catch (RemoteException e) {
|
||||
exceptionImplementation(-1, e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void getKeyringsBytesOnClick(View view) {
|
||||
try {
|
||||
service.getPublicKeyRings(mApgData.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 IApgGetKeyringsHandler.Stub getKeyringsHandler = new IApgGetKeyringsHandler.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) {
|
||||
mApgIntentHelper.selectPublicKeys("user@example.com");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
// this updates the mApgData object to the result of the methods
|
||||
boolean result = mApgIntentHelper.onActivityResult(requestCode, resultCode, data, mApgData);
|
||||
if (result) {
|
||||
updateView();
|
||||
}
|
||||
|
||||
// continue with other activity results
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,8 +29,9 @@ public class BaseActivity extends PreferenceActivity {
|
||||
private Activity mActivity;
|
||||
|
||||
private Preference mIntentDemo;
|
||||
private Preference mAidlDemo;
|
||||
private Preference mContentProviderDemo;
|
||||
private Preference mAidlDemo;
|
||||
private Preference mAidlDemo2;
|
||||
|
||||
/**
|
||||
* Called when the activity is first created.
|
||||
@@ -46,8 +47,9 @@ public class BaseActivity extends PreferenceActivity {
|
||||
|
||||
// find preferences
|
||||
mIntentDemo = (Preference) findPreference("intent_demo");
|
||||
mAidlDemo = (Preference) findPreference("aidl_demo");
|
||||
mContentProviderDemo = (Preference) findPreference("content_provider_demo");
|
||||
mAidlDemo = (Preference) findPreference("aidl_demo");
|
||||
mAidlDemo2 = (Preference) findPreference("aidl_demo2");
|
||||
|
||||
mIntentDemo.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||
@Override
|
||||
@@ -58,6 +60,15 @@ public class BaseActivity extends PreferenceActivity {
|
||||
}
|
||||
});
|
||||
|
||||
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) {
|
||||
@@ -67,14 +78,15 @@ public class BaseActivity extends PreferenceActivity {
|
||||
}
|
||||
});
|
||||
|
||||
mContentProviderDemo.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||
mAidlDemo2.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
startActivity(new Intent(mActivity, ContentProviderDemoActivity.class));
|
||||
startActivity(new Intent(mActivity, AidlDemoActivity2.class));
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -65,17 +65,17 @@ public class IntentDemoActivity extends Activity {
|
||||
}
|
||||
|
||||
public void selectEncryptionKeysOnClick(View view) {
|
||||
mApgIntentHelper.selectEncryptionKeys("user@example.com");
|
||||
mApgIntentHelper.selectPublicKeys("user@example.com");
|
||||
}
|
||||
|
||||
public void encryptOnClick(View view) {
|
||||
mApgIntentHelper.encrypt(mMessageTextView.getText().toString(),
|
||||
mApgData.getEncryptionKeys(), mApgData.getSignatureKeyId(), false);
|
||||
mApgIntentHelper.encrypt(mMessageTextView.getText().toString(), mApgData.getPublicKeys(),
|
||||
mApgData.getSecretKeyId(), false);
|
||||
}
|
||||
|
||||
public void encryptAndReturnOnClick(View view) {
|
||||
mApgIntentHelper.encrypt(mMessageTextView.getText().toString(),
|
||||
mApgData.getEncryptionKeys(), mApgData.getSignatureKeyId(), true);
|
||||
mApgIntentHelper.encrypt(mMessageTextView.getText().toString(), mApgData.getPublicKeys(),
|
||||
mApgData.getSecretKeyId(), true);
|
||||
}
|
||||
|
||||
public void decryptOnClick(View view) {
|
||||
|
||||
Reference in New Issue
Block a user