passphraseactivity: add inline spinner to password dialog
This commit is contained in:
@@ -171,27 +171,6 @@ public class EditKeyOperation extends BaseOperation<SaveKeyringParcel> {
|
|||||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
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);
|
updateProgress(R.string.progress_done, 100, 100);
|
||||||
|
|
||||||
// make sure new data is synced into contacts
|
// make sure new data is synced into contacts
|
||||||
|
|||||||
@@ -120,13 +120,14 @@ public class PassphraseCacheService extends Service {
|
|||||||
*/
|
*/
|
||||||
public static void addCachedPassphrase(Context context, long masterKeyId, long subKeyId,
|
public static void addCachedPassphrase(Context context, long masterKeyId, long subKeyId,
|
||||||
Passphrase passphrase,
|
Passphrase passphrase,
|
||||||
String primaryUserId) {
|
String primaryUserId,
|
||||||
|
long timeToLiveSeconds) {
|
||||||
Log.d(Constants.TAG, "PassphraseCacheService.addCachedPassphrase() for " + masterKeyId);
|
Log.d(Constants.TAG, "PassphraseCacheService.addCachedPassphrase() for " + masterKeyId);
|
||||||
|
|
||||||
Intent intent = new Intent(context, PassphraseCacheService.class);
|
Intent intent = new Intent(context, PassphraseCacheService.class);
|
||||||
intent.setAction(ACTION_PASSPHRASE_CACHE_ADD);
|
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_PASSPHRASE, passphrase);
|
||||||
intent.putExtra(EXTRA_KEY_ID, masterKeyId);
|
intent.putExtra(EXTRA_KEY_ID, masterKeyId);
|
||||||
intent.putExtra(EXTRA_SUBKEY_ID, subKeyId);
|
intent.putExtra(EXTRA_SUBKEY_ID, subKeyId);
|
||||||
@@ -237,7 +238,8 @@ public class PassphraseCacheService extends Service {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
addCachedPassphrase(this, Constants.key.symmetric, Constants.key.symmetric,
|
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();
|
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();
|
return cachedPassphrase.getPassphrase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
|||||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder;
|
import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder;
|
||||||
import org.sufficientlysecure.keychain.ui.util.ThemeChanger;
|
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.Log;
|
||||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
@@ -200,6 +201,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
|
|
||||||
private Intent mServiceIntent;
|
private Intent mServiceIntent;
|
||||||
private ViewAnimator mLayout;
|
private ViewAnimator mLayout;
|
||||||
|
private CacheTTLSpinner mTimeToLiveSpinner;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
@@ -241,6 +243,8 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
mPassphraseText = (TextView) mLayout.findViewById(R.id.passphrase_text);
|
mPassphraseText = (TextView) mLayout.findViewById(R.id.passphrase_text);
|
||||||
mPassphraseEditText = (EditText) mLayout.findViewById(R.id.passphrase_passphrase);
|
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() {
|
alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -415,12 +419,14 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
CryptoInputParcel cryptoInputParcel =
|
CryptoInputParcel cryptoInputParcel =
|
||||||
((PassphraseDialogActivity) getActivity()).mCryptoInputParcel;
|
((PassphraseDialogActivity) getActivity()).mCryptoInputParcel;
|
||||||
|
|
||||||
|
final long timeToLiveSeconds = mTimeToLiveSpinner.getSelectedTimeToLive();
|
||||||
|
|
||||||
// Early breakout if we are dealing with a symmetric key
|
// Early breakout if we are dealing with a symmetric key
|
||||||
if (mSecretRing == null) {
|
if (mSecretRing == null) {
|
||||||
if (cryptoInputParcel.mCachePassphrase) {
|
if (cryptoInputParcel.mCachePassphrase) {
|
||||||
PassphraseCacheService.addCachedPassphrase(getActivity(),
|
PassphraseCacheService.addCachedPassphrase(getActivity(),
|
||||||
Constants.key.symmetric, Constants.key.symmetric, passphrase,
|
Constants.key.symmetric, Constants.key.symmetric, passphrase,
|
||||||
getString(R.string.passp_cache_notif_pwd));
|
getString(R.string.passp_cache_notif_pwd), timeToLiveSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
finishCaching(passphrase);
|
finishCaching(passphrase);
|
||||||
@@ -484,7 +490,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
try {
|
try {
|
||||||
PassphraseCacheService.addCachedPassphrase(getActivity(),
|
PassphraseCacheService.addCachedPassphrase(getActivity(),
|
||||||
mSecretRing.getMasterKeyId(), mSubKeyId, passphrase,
|
mSecretRing.getMasterKeyId(), mSubKeyId, passphrase,
|
||||||
mSecretRing.getPrimaryUserIdWithFallback());
|
mSecretRing.getPrimaryUserIdWithFallback(), timeToLiveSeconds);
|
||||||
} catch (PgpKeyNotFoundException e) {
|
} catch (PgpKeyNotFoundException e) {
|
||||||
Log.e(Constants.TAG, "adding of a passphrase failed", e);
|
Log.e(Constants.TAG, "adding of a passphrase failed", e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
xmlns:custom="http://schemas.android.com/apk/res-auto"
|
xmlns:custom="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:paddingTop="16dp"
|
android:paddingTop="16dp"
|
||||||
android:paddingBottom="16dp"
|
android:paddingBottom="16dp"
|
||||||
android:paddingLeft="24dp"
|
android:paddingLeft="24dp"
|
||||||
@@ -33,6 +34,27 @@
|
|||||||
android:ems="10"
|
android:ems="10"
|
||||||
android:layout_gravity="center_horizontal" />
|
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>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|||||||
16
OpenKeychain/src/main/res/layout/simple_item.xml
Normal file
16
OpenKeychain/src/main/res/layout/simple_item.xml
Normal file
@@ -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>
|
||||||
Reference in New Issue
Block a user