aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2015-11-13 16:56:35 +0100
committerVincent Breitmoser <valodim@mugenguild.com>2016-01-06 16:24:07 +0100
commit840d57bf3b2c91f63f0df9d8988c16eb467b4a29 (patch)
tree7398afaf2f024d097b72e78e82ac305c8bcfab79 /OpenKeychain/src/main
parentf8d6b0bb467cf126b3e1bf295f584b533280ebef (diff)
downloadopen-keychain-840d57bf3b2c91f63f0df9d8988c16eb467b4a29.tar.gz
open-keychain-840d57bf3b2c91f63f0df9d8988c16eb467b4a29.tar.bz2
open-keychain-840d57bf3b2c91f63f0df9d8988c16eb467b4a29.zip
passphraseactivity: add inline spinner to password dialog
Diffstat (limited to 'OpenKeychain/src/main')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/EditKeyOperation.java21
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java11
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java10
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/CacheTTLSpinner.java79
-rw-r--r--OpenKeychain/src/main/res/layout/passphrase_dialog.xml22
-rw-r--r--OpenKeychain/src/main/res/layout/simple_item.xml16
6 files changed, 130 insertions, 29 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/EditKeyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/EditKeyOperation.java
index 51485a35d..8af2fdc67 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/EditKeyOperation.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/EditKeyOperation.java
@@ -171,27 +171,6 @@ public class EditKeyOperation extends BaseOperation<SaveKeyringParcel> {
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
}
- // There is a new passphrase - cache it
- if (saveParcel.mNewUnlock != null && cryptoInput.mCachePassphrase) {
- log.add(LogType.MSG_ED_CACHING_NEW, 1);
-
- // NOTE: Don't cache empty passphrases! Important for MOVE_KEY_TO_CARD
- if (saveParcel.mNewUnlock.mNewPassphrase != null
- && ( ! saveParcel.mNewUnlock.mNewPassphrase.isEmpty())) {
- PassphraseCacheService.addCachedPassphrase(mContext,
- ring.getMasterKeyId(),
- ring.getMasterKeyId(),
- saveParcel.mNewUnlock.mNewPassphrase,
- ring.getPublicKey().getPrimaryUserIdWithFallback());
- } else if (saveParcel.mNewUnlock.mNewPin != null) {
- PassphraseCacheService.addCachedPassphrase(mContext,
- ring.getMasterKeyId(),
- ring.getMasterKeyId(),
- saveParcel.mNewUnlock.mNewPin,
- ring.getPublicKey().getPrimaryUserIdWithFallback());
- }
- }
-
updateProgress(R.string.progress_done, 100, 100);
// make sure new data is synced into contacts
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java
index 73da3aff9..d4f4998a5 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java
@@ -120,13 +120,14 @@ public class PassphraseCacheService extends Service {
*/
public static void addCachedPassphrase(Context context, long masterKeyId, long subKeyId,
Passphrase passphrase,
- String primaryUserId) {
+ String primaryUserId,
+ long timeToLiveSeconds) {
Log.d(Constants.TAG, "PassphraseCacheService.addCachedPassphrase() for " + masterKeyId);
Intent intent = new Intent(context, PassphraseCacheService.class);
intent.setAction(ACTION_PASSPHRASE_CACHE_ADD);
- intent.putExtra(EXTRA_TTL, Preferences.getPreferences(context).getPassphraseCacheTtl());
+ intent.putExtra(EXTRA_TTL, timeToLiveSeconds);
intent.putExtra(EXTRA_PASSPHRASE, passphrase);
intent.putExtra(EXTRA_KEY_ID, masterKeyId);
intent.putExtra(EXTRA_SUBKEY_ID, subKeyId);
@@ -237,7 +238,8 @@ public class PassphraseCacheService extends Service {
return null;
}
addCachedPassphrase(this, Constants.key.symmetric, Constants.key.symmetric,
- cachedPassphrase.getPassphrase(), getString(R.string.passp_cache_notif_pwd));
+ cachedPassphrase.getPassphrase(), getString(R.string.passp_cache_notif_pwd),
+ Preferences.getPreferences(getBaseContext()).getPassphraseCacheTtl());
return cachedPassphrase.getPassphrase();
}
@@ -285,9 +287,6 @@ public class PassphraseCacheService extends Service {
}
- // set it again to reset the cache life cycle
- Log.d(Constants.TAG, "PassphraseCacheService: Cache passphrase again when getting it!");
- addCachedPassphrase(this, masterKeyId, subKeyId, cachedPassphrase.getPassphrase(), cachedPassphrase.getPrimaryUserID());
return cachedPassphrase.getPassphrase();
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java
index 897719fc2..2ddbe376b 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java
@@ -63,6 +63,7 @@ import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder;
import org.sufficientlysecure.keychain.ui.util.ThemeChanger;
+import org.sufficientlysecure.keychain.ui.widget.CacheTTLSpinner;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Passphrase;
import org.sufficientlysecure.keychain.util.Preferences;
@@ -200,6 +201,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
private Intent mServiceIntent;
private ViewAnimator mLayout;
+ private CacheTTLSpinner mTimeToLiveSpinner;
@NonNull
@Override
@@ -241,6 +243,8 @@ public class PassphraseDialogActivity extends FragmentActivity {
mPassphraseText = (TextView) mLayout.findViewById(R.id.passphrase_text);
mPassphraseEditText = (EditText) mLayout.findViewById(R.id.passphrase_passphrase);
+ mTimeToLiveSpinner = (CacheTTLSpinner) mLayout.findViewById(R.id.ttl_spinner);
+
alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
@@ -415,12 +419,14 @@ public class PassphraseDialogActivity extends FragmentActivity {
CryptoInputParcel cryptoInputParcel =
((PassphraseDialogActivity) getActivity()).mCryptoInputParcel;
+ final long timeToLiveSeconds = mTimeToLiveSpinner.getSelectedTimeToLive();
+
// Early breakout if we are dealing with a symmetric key
if (mSecretRing == null) {
if (cryptoInputParcel.mCachePassphrase) {
PassphraseCacheService.addCachedPassphrase(getActivity(),
Constants.key.symmetric, Constants.key.symmetric, passphrase,
- getString(R.string.passp_cache_notif_pwd));
+ getString(R.string.passp_cache_notif_pwd), timeToLiveSeconds);
}
finishCaching(passphrase);
@@ -484,7 +490,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
try {
PassphraseCacheService.addCachedPassphrase(getActivity(),
mSecretRing.getMasterKeyId(), mSubKeyId, passphrase,
- mSecretRing.getPrimaryUserIdWithFallback());
+ mSecretRing.getPrimaryUserIdWithFallback(), timeToLiveSeconds);
} catch (PgpKeyNotFoundException e) {
Log.e(Constants.TAG, "adding of a passphrase failed", e);
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/CacheTTLSpinner.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/CacheTTLSpinner.java
new file mode 100644
index 000000000..9a8a2f1d1
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/CacheTTLSpinner.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2015 Vincent Breitmoser <v.breitmoser@my.amazin.horse>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package org.sufficientlysecure.keychain.ui.widget;
+
+
+import android.content.Context;
+import android.content.res.Resources.Theme;
+import android.database.Cursor;
+import android.database.MatrixCursor;
+import android.os.Bundle;
+import android.os.Parcelable;
+import android.support.annotation.NonNull;
+import android.support.annotation.StringRes;
+import android.support.v4.widget.SimpleCursorAdapter;
+import android.support.v7.widget.AppCompatSpinner;
+import android.util.AttributeSet;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.BaseAdapter;
+import android.widget.SpinnerAdapter;
+import android.widget.TextView;
+
+import org.sufficientlysecure.keychain.Constants;
+import org.sufficientlysecure.keychain.R;
+import org.sufficientlysecure.keychain.provider.KeychainContract;
+import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter;
+import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter.KeyItem;
+
+
+public class CacheTTLSpinner extends AppCompatSpinner {
+
+ public CacheTTLSpinner(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ initView();
+ }
+
+ public CacheTTLSpinner(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ initView();
+ }
+
+ private void initView() {
+ MatrixCursor cursor = new MatrixCursor(new String[] { "_id", "TTL", "description" }, 5);
+ cursor.addRow(new Object[] { 0, 60*5, "Five Minutes" });
+ cursor.addRow(new Object[] { 1, 60*60, "One Hour" });
+ cursor.addRow(new Object[] { 2, 60*60*3, "Three Hours" });
+ cursor.addRow(new Object[] { 3, 60*60*24, "One Day" });
+ cursor.addRow(new Object[] { 4, 60*60*24*3, "Three Days" });
+
+ setAdapter(new SimpleCursorAdapter(getContext(), R.layout.simple_item, cursor,
+ new String[] { "description" },
+ new int[] { R.id.simple_item_text },
+ 0));
+ }
+
+ public long getSelectedTimeToLive() {
+ int selectedItemPosition = getSelectedItemPosition();
+ Object item = getAdapter().getItem(selectedItemPosition);
+ return ((Cursor) item).getLong(0);
+ }
+
+}
diff --git a/OpenKeychain/src/main/res/layout/passphrase_dialog.xml b/OpenKeychain/src/main/res/layout/passphrase_dialog.xml
index cd6b3e87b..fe09fb405 100644
--- a/OpenKeychain/src/main/res/layout/passphrase_dialog.xml
+++ b/OpenKeychain/src/main/res/layout/passphrase_dialog.xml
@@ -4,6 +4,7 @@
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ xmlns:tools="http://schemas.android.com/tools"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingLeft="24dp"
@@ -33,6 +34,27 @@
android:ems="10"
android:layout_gravity="center_horizontal" />
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:gravity="center_vertical"
+ android:layout_margin="6dp">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Remember for "
+ android:textAppearance="@android:style/TextAppearance.Medium" />
+
+ <org.sufficientlysecure.keychain.ui.widget.CacheTTLSpinner
+ android:id="@+id/ttl_spinner"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content">
+ </org.sufficientlysecure.keychain.ui.widget.CacheTTLSpinner>
+
+ </LinearLayout>
+
</LinearLayout>
<LinearLayout
diff --git a/OpenKeychain/src/main/res/layout/simple_item.xml b/OpenKeychain/src/main/res/layout/simple_item.xml
new file mode 100644
index 000000000..9a7bc58e3
--- /dev/null
+++ b/OpenKeychain/src/main/res/layout/simple_item.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:id="@+id/simple_item_text"
+ android:textAppearance="@android:style/TextAppearance.Medium"
+ tools:text="itemtext" />
+</LinearLayout> \ No newline at end of file