From 202ccc2c36d191fbecdcc3098875dd075454c71a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Mon, 1 Jul 2013 23:19:53 +0200 Subject: More work on crypto consumers --- .../org/openintents/crypto/ICryptoCallback.aidl | 8 +- .../src/org/openintents/crypto/ICryptoService.aidl | 8 +- .../src/org/sufficientlysecure/keychain/Id.java | 1 + .../keychain/crypto_provider/CryptoService.java | 9 ++- .../keychain/ui/CryptoConsumersActivity.java | 43 +++++++++++ .../keychain/ui/CryptoConsumersFragment.java | 85 ++++++++++++++++++++++ .../keychain/ui/MainActivity.java | 7 ++ 7 files changed, 156 insertions(+), 5 deletions(-) create mode 100644 OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/CryptoConsumersActivity.java create mode 100644 OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/CryptoConsumersFragment.java (limited to 'OpenPGP-Keychain/src/org') diff --git a/OpenPGP-Keychain/src/org/openintents/crypto/ICryptoCallback.aidl b/OpenPGP-Keychain/src/org/openintents/crypto/ICryptoCallback.aidl index 80c741a9e..1f910d4c6 100644 --- a/OpenPGP-Keychain/src/org/openintents/crypto/ICryptoCallback.aidl +++ b/OpenPGP-Keychain/src/org/openintents/crypto/ICryptoCallback.aidl @@ -20,10 +20,12 @@ import org.openintents.crypto.CryptoSignatureResult; import org.openintents.crypto.CryptoError; interface ICryptoCallback { - - oneway void onEncryptSignSuccess(in byte[] outputBytes); - oneway void onDecryptVerifySuccess(in byte[] outputBytes, in CryptoSignatureResult signatureResult); + /** + * CryptoSignatureResult is only returned if the Callback was used from decryptAndVerify + * + */ + oneway void onSuccess(in byte[] outputBytes, in CryptoSignatureResult signatureResult); oneway void onError(in CryptoError error); diff --git a/OpenPGP-Keychain/src/org/openintents/crypto/ICryptoService.aidl b/OpenPGP-Keychain/src/org/openintents/crypto/ICryptoService.aidl index 53f39dffc..c84ca28fb 100644 --- a/OpenPGP-Keychain/src/org/openintents/crypto/ICryptoService.aidl +++ b/OpenPGP-Keychain/src/org/openintents/crypto/ICryptoService.aidl @@ -71,6 +71,12 @@ interface ICryptoService { * @param callback * Callback where to return results */ - oneway void decryptAndVerify(in byte[] inputBytes, in ICryptoCallback callback); + oneway void decryptAndVerify(in byte[] inputBytes, in ICryptoCallback callback); + + /** + * Opens setup using default parameters + * + */ + oneway void setup(boolean asciiArmor, boolean newKeyring, String newKeyringUserId); } \ No newline at end of file diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/Id.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/Id.java index 382f144d7..b0d60cf94 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/Id.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/Id.java @@ -62,6 +62,7 @@ public final class Id { public static final int import_from_file = 0x21070020; public static final int import_from_qr_code = 0x21070021; public static final int import_from_nfc = 0x21070022; + public static final int crypto_consumers = 0x21070023; } } diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/CryptoService.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/CryptoService.java index 7ff8c0e3e..e601620ea 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/CryptoService.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/CryptoService.java @@ -184,7 +184,7 @@ public class CryptoService extends Service { signatureSuccess, signatureUnknown); // return over handler on client side - callback.onDecryptVerifySuccess(outputBytes, sigResult); + callback.onSuccess(outputBytes, sigResult); } catch (Exception e) { Log.e(Constants.TAG, "KeychainService, Exception!", e); @@ -250,6 +250,13 @@ public class CryptoService extends Service { checkAndEnqueue(r); } + @Override + public void setup(boolean asciiArmor, boolean newKeyring, String newKeyringUserId) + throws RemoteException { + // TODO Auto-generated method stub + + } + }; private final IServiceActivityCallback.Stub mBinderServiceActivity = new IServiceActivityCallback.Stub() { diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/CryptoConsumersActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/CryptoConsumersActivity.java new file mode 100644 index 000000000..59eaa063f --- /dev/null +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/CryptoConsumersActivity.java @@ -0,0 +1,43 @@ +package org.sufficientlysecure.keychain.ui; + +import org.sufficientlysecure.keychain.R; + +import com.actionbarsherlock.app.ActionBar; +import com.actionbarsherlock.app.SherlockFragmentActivity; +import com.actionbarsherlock.view.MenuItem; + +import android.content.Intent; +import android.os.Bundle; + +public class CryptoConsumersActivity extends SherlockFragmentActivity { + private ActionBar mActionBar; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + mActionBar = getSupportActionBar(); + + setContentView(R.layout.crypto_consumers_activity); + + mActionBar.setDisplayShowTitleEnabled(true); + mActionBar.setDisplayHomeAsUpEnabled(true); + } + + /** + * Menu Options + */ + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + // app icon in Action Bar clicked; go home + Intent intent = new Intent(this, MainActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(intent); + return true; + default: + return super.onOptionsItemSelected(item); + } + } +} diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/CryptoConsumersFragment.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/CryptoConsumersFragment.java new file mode 100644 index 000000000..8ecc5ced1 --- /dev/null +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/CryptoConsumersFragment.java @@ -0,0 +1,85 @@ +package org.sufficientlysecure.keychain.ui; + +import org.sufficientlysecure.keychain.provider.KeychainContract.CryptoConsumers; +import org.sufficientlysecure.keychain.util.Log; + +import com.actionbarsherlock.app.SherlockListFragment; +import android.database.Cursor; +import android.net.Uri; +import android.os.Bundle; +import android.support.v4.app.LoaderManager; +import android.support.v4.content.CursorLoader; +import android.support.v4.content.Loader; +import android.support.v4.widget.SimpleCursorAdapter; + +import android.view.View; +import android.widget.ListView; + +public class CryptoConsumersFragment extends SherlockListFragment implements + LoaderManager.LoaderCallbacks { + + // This is the Adapter being used to display the list's data. + SimpleCursorAdapter mAdapter; + + // If non-null, this is the current filter the user has provided. + String mCurFilter; + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + // Give some text to display if there is no data. In a real + // application this would come from a resource. + setEmptyText("TODO no crypto consumers"); + + // We have a menu item to show in action bar. + setHasOptionsMenu(true); + + // Create an empty adapter we will use to display the loaded data. + mAdapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_2, + null, new String[] { CryptoConsumers.PACKAGE_NAME, CryptoConsumers.PACKAGE_NAME }, + new int[] { android.R.id.text1, android.R.id.text2 }, 0); + setListAdapter(mAdapter); + + // Prepare the loader. Either re-connect with an existing one, + // or start a new one. + getLoaderManager().initLoader(0, null, this); + } + + @Override + public void onListItemClick(ListView l, View v, int position, long id) { + // Insert desired behavior here. + Log.i("FragmentComplexList", "Item clicked: " + id); + } + + // These are the Contacts rows that we will retrieve. + static final String[] CONSUMERS_SUMMARY_PROJECTION = new String[] { CryptoConsumers._ID, + CryptoConsumers.PACKAGE_NAME }; + + public Loader onCreateLoader(int id, Bundle args) { + // This is called when a new Loader needs to be created. This + // sample only has one Loader, so we don't care about the ID. + // First, pick the base URI to use depending on whether we are + // currently filtering. + Uri baseUri = CryptoConsumers.CONTENT_URI; + + // Now create and return a CursorLoader that will take care of + // creating a Cursor for the data being displayed. + return new CursorLoader(getActivity(), baseUri, CONSUMERS_SUMMARY_PROJECTION, null, null, + CryptoConsumers.PACKAGE_NAME + " COLLATE LOCALIZED ASC"); + } + + public void onLoadFinished(Loader loader, Cursor data) { + // Swap the new cursor in. (The framework will take care of closing the + // old cursor once we return.) + mAdapter.swapCursor(data); + } + + public void onLoaderReset(Loader loader) { + // This is called when the last Cursor provided to onLoadFinished() + // above is about to be closed. We need to make sure we are no + // longer using it. + mAdapter.swapCursor(null); + } + +} \ No newline at end of file diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/MainActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/MainActivity.java index 447801e55..a108b3db4 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/MainActivity.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/MainActivity.java @@ -80,6 +80,9 @@ public class MainActivity extends SherlockActivity { menu.add(0, Id.menu.option.preferences, 0, R.string.menu_preferences) .setIcon(R.drawable.ic_menu_settings) .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); + menu.add(0, Id.menu.option.crypto_consumers, 0, R.string.menu_crypto_consumers) + .setIcon(R.drawable.ic_menu_settings) + .setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT); return true; } @@ -91,6 +94,10 @@ public class MainActivity extends SherlockActivity { startActivity(new Intent(this, PreferencesActivity.class)); return true; + case Id.menu.option.crypto_consumers: + startActivity(new Intent(this, CryptoConsumersActivity.class)); + return true; + default: break; -- cgit v1.2.3