aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2015-11-04 20:24:11 +0100
committerVincent Breitmoser <valodim@mugenguild.com>2015-11-04 20:24:11 +0100
commit3ca8af060b2f6452df794a8770714d1f02b36734 (patch)
tree438d92f9107bd76e10c5f72f41c4d7bc12e44ced /OpenKeychain/src
parenta4518c43c2fdff3852668242978a8b9739447d0b (diff)
parent31a45759ccfbca76f89e6e51bf94c4a3af3a874f (diff)
downloadopen-keychain-3ca8af060b2f6452df794a8770714d1f02b36734.tar.gz
open-keychain-3ca8af060b2f6452df794a8770714d1f02b36734.tar.bz2
open-keychain-3ca8af060b2f6452df794a8770714d1f02b36734.zip
Merge branch 'master' of github.com:open-keychain/open-keychain
Diffstat (limited to 'OpenKeychain/src')
-rw-r--r--OpenKeychain/src/main/AndroidManifest.xml62
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportOperation.java4
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java122
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java30
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextFragment.java22
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeCaptureActivity.java92
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java33
-rw-r--r--OpenKeychain/src/main/res/drawable-hdpi/ic_action_encrypt_paste_24dp.pngbin0 -> 590 bytes
-rw-r--r--OpenKeychain/src/main/res/drawable-mdpi/ic_action_encrypt_paste_24dp.pngbin0 -> 433 bytes
-rw-r--r--OpenKeychain/src/main/res/drawable-xhdpi/ic_action_encrypt_paste_24dp.pngbin0 -> 684 bytes
-rw-r--r--OpenKeychain/src/main/res/drawable-xhdpi/status_signature_expired_cutout_96dp.pngbin0 -> 4973 bytes
-rw-r--r--OpenKeychain/src/main/res/drawable-xxhdpi/ic_action_encrypt_paste_24dp.pngbin0 -> 986 bytes
-rw-r--r--OpenKeychain/src/main/res/drawable-xxxhdpi/ic_action_encrypt_paste_24dp.pngbin0 -> 1290 bytes
-rw-r--r--OpenKeychain/src/main/res/menu/encrypt_text_fragment.xml8
-rw-r--r--OpenKeychain/src/main/res/values-v23/themes.xml7
-rw-r--r--OpenKeychain/src/main/res/values/strings.xml1
-rw-r--r--OpenKeychain/src/main/res/values/themes.xml8
17 files changed, 300 insertions, 89 deletions
diff --git a/OpenKeychain/src/main/AndroidManifest.xml b/OpenKeychain/src/main/AndroidManifest.xml
index 8730a456e..79b8dbb27 100644
--- a/OpenKeychain/src/main/AndroidManifest.xml
+++ b/OpenKeychain/src/main/AndroidManifest.xml
@@ -53,19 +53,32 @@
android:name="${applicationId}.WRITE_TEMPORARY_STORAGE"
android:protectionLevel="signature" />
- <uses-permission android:name="android.permission.INTERNET" />
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
- <uses-permission android:name="android.permission.NFC" />
+ <!-- CAMERA permission requested by ZXing library -->
+
+ <!-- contact group -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
- <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
- <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.WRITE_PROFILE" />
+ <!-- storage group -->
+ <!--
+ No need on >= Android 4.4 for WRITE_EXTERNAL_STORAGE, because we use Storage Access Framework,
+ but better not use maxSdkVersion as it causes problems: https://code.google.com/p/android/issues/detail?id=63895
+ -->
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <!-- READ_EXTERNAL_STORAGE is now dangerous on Android >= 6 -->
+ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+
+ <!-- other group (for free) -->
+ <uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.NFC" />
+ <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
+ <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
+
<!-- android:allowBackup="false": Don't allow backup over adb backup or other apps! -->
<application
android:name=".KeychainApplication"
@@ -97,12 +110,12 @@
android:value=".ui.MainActivity" />
<!-- Connect with YubiKeys. This Activity will automatically show/import/create YubiKeys -->
<intent-filter android:label="@string/app_name">
- <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
- <category android:name="android.intent.category.DEFAULT"/>
+ <action android:name="android.nfc.action.NDEF_DISCOVERED" />
+ <category android:name="android.intent.category.DEFAULT" />
<data
- android:scheme="https"
android:host="my.yubico.com"
- android:pathPrefix="/neo"/>
+ android:pathPrefix="/neo"
+ android:scheme="https" />
</intent-filter>
</activity>
<activity
@@ -114,9 +127,7 @@
android:name=".ui.linked.LinkedIdWizard"
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
android:label="@string/title_linked_create"
- android:parentActivityName=".ui.ViewKeyActivity"
- >
- </activity>
+ android:parentActivityName=".ui.ViewKeyActivity"></activity>
<activity
android:name=".ui.QrCodeViewActivity"
android:label="@string/share_qr_code_dialog_title" />
@@ -210,6 +221,12 @@
<data android:mimeType="text/*" />
<data android:mimeType="message/*" />
</intent-filter>
+ <!-- Android 6 Floating Action Mode -->
+ <intent-filter>
+ <action android:name="android.intent.action.PROCESS_TEXT" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <data android:mimeType="text/plain" />
+ </intent-filter>
</activity>
<activity
android:name=".ui.DisplayTextActivity"
@@ -466,7 +483,7 @@
android:name=".ui.ImportKeysProxyActivity"
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
android:label="@string/app_name"
- android:theme="@android:style/Theme.NoDisplay"
+ android:theme="@style/Theme.Keychain.Transparent"
android:windowSoftInputMode="stateHidden">
<!-- VIEW with fingerprint scheme:
@@ -499,8 +516,7 @@
<data android:mimeType="application/pgp-keys" />
</intent-filter>
</activity>
- <activity
- android:name=".ui.QrCodeCaptureActivity"/>
+ <activity android:name=".ui.QrCodeCaptureActivity" />
<activity
android:name=".ui.ImportKeysActivity"
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
@@ -692,19 +708,19 @@
android:label="@string/title_log_display" />
<activity
android:name=".ui.ConsolidateDialogActivity"
- android:theme="@android:style/Theme.NoDisplay" />
+ android:theme="@style/Theme.Keychain.Transparent" />
<activity
android:name=".ui.PassphraseDialogActivity"
- android:theme="@android:style/Theme.NoDisplay" />
+ android:theme="@style/Theme.Keychain.Transparent" />
<activity
android:name=".ui.RetryUploadDialogActivity"
- android:theme="@android:style/Theme.NoDisplay" />
+ android:theme="@style/Theme.Keychain.Transparent" />
<activity
android:name=".ui.DeleteKeyDialogActivity"
- android:theme="@android:style/Theme.NoDisplay" />
+ android:theme="@style/Theme.Keychain.Transparent" />
<activity
android:name=".ui.OrbotRequiredDialogActivity"
- android:theme="@android:style/Theme.NoDisplay" />
+ android:theme="@style/Theme.Keychain.Transparent" />
<!--
NOTE: singleTop is set to get NFC foreground dispatch to work.
Then, all NFC intents will be broadcasted to onNewIntent() of this activity!
@@ -714,10 +730,10 @@
-->
<activity
android:name=".ui.NfcOperationActivity"
- android:theme="@style/Theme.Keychain.Light.Dialog"
android:allowTaskReparenting="true"
android:launchMode="singleTop"
- android:taskAffinity=":Nfc" />
+ android:taskAffinity=":Nfc"
+ android:theme="@style/Theme.Keychain.Light.Dialog" />
<activity
android:name=".ui.HelpActivity"
@@ -742,7 +758,7 @@
android:name=".provider.KeychainProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
- android:label="@string/keyserver_sync_settings_title"/>
+ android:label="@string/keyserver_sync_settings_title" />
<!-- Internal classes of the remote APIs (not exported) -->
<activity
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportOperation.java
index 8a4998b8f..19a05790f 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportOperation.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportOperation.java
@@ -540,7 +540,9 @@ public class ImportOperation extends BaseOperation<ImportKeyringParcel> {
// adding required information to mResultType
// special case,no keys requested for import
- if (mBadKeys == 0 && mNewKeys == 0 && mUpdatedKeys == 0) {
+ if (mBadKeys == 0 && mNewKeys == 0 && mUpdatedKeys == 0
+ && (mResultType & ImportKeyResult.RESULT_CANCELLED)
+ != ImportKeyResult.RESULT_CANCELLED) {
mResultType = ImportKeyResult.RESULT_FAIL_NOTHING;
} else {
if (mNewKeys > 0) {
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java
index 8aebae7aa..122eb6cf4 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java
@@ -59,11 +59,12 @@ public class KeyserverSyncAdapterService extends Service {
// time since last update after which a key should be updated again, in s
public static final long KEY_UPDATE_LIMIT =
Constants.DEBUG_KEYSERVER_SYNC ? 1 : TimeUnit.DAYS.toSeconds(7);
- // time by which a sync is postponed in case of a
+ // time by which a sync is postponed in case screen is on
public static final long SYNC_POSTPONE_TIME =
Constants.DEBUG_KEYSERVER_SYNC ? 30 * 1000 : TimeUnit.MINUTES.toMillis(5);
// Time taken by Orbot before a new circuit is created
- public static final int ORBOT_CIRCUIT_TIMEOUT = (int) TimeUnit.MINUTES.toMillis(10);
+ public static final int ORBOT_CIRCUIT_TIMEOUT_SECONDS =
+ Constants.DEBUG_KEYSERVER_SYNC ? 2 : (int) TimeUnit.MINUTES.toSeconds(10);
private static final String ACTION_IGNORE_TOR = "ignore_tor";
@@ -77,10 +78,14 @@ public class KeyserverSyncAdapterService extends Service {
@Override
public int onStartCommand(final Intent intent, int flags, final int startId) {
+ if (intent == null || intent.getAction() == null) {
+ // introduced due to https://github.com/open-keychain/open-keychain/issues/1573
+ return START_NOT_STICKY; // we can't act on this Intent and don't want it redelivered
+ }
switch (intent.getAction()) {
case ACTION_CANCEL: {
mCancelled.set(true);
- break;
+ return START_NOT_STICKY;
}
// the reason for the separation betweyeen SYNC_NOW and UPDATE_ALL is so that starting
// the sync directly from the notification is possible while the screen is on with
@@ -92,44 +97,47 @@ public class KeyserverSyncAdapterService extends Service {
Constants.PROVIDER_AUTHORITY,
new Bundle()
);
- break;
+ return START_NOT_STICKY;
}
case ACTION_UPDATE_ALL: {
// does not check for screen on/off
- asyncKeyUpdate(this, new CryptoInputParcel());
- break;
+ asyncKeyUpdate(this, new CryptoInputParcel(), startId);
+ // we depend on handleUpdateResult to call stopSelf when it is no longer necessary
+ // for the intent to be redelivered
+ return START_REDELIVER_INTENT;
}
case ACTION_IGNORE_TOR: {
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.cancel(Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT);
- asyncKeyUpdate(this, new CryptoInputParcel(ParcelableProxy.getForNoProxy()));
- break;
+ asyncKeyUpdate(this, new CryptoInputParcel(ParcelableProxy.getForNoProxy()),
+ startId);
+ // we depend on handleUpdateResult to call stopSelf when it is no longer necessary
+ // for the intent to be redelivered
+ return START_REDELIVER_INTENT;
}
case ACTION_START_ORBOT: {
- NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+ NotificationManager manager = (NotificationManager)
+ getSystemService(NOTIFICATION_SERVICE);
manager.cancel(Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT);
+
Intent startOrbot = new Intent(this, OrbotRequiredDialogActivity.class);
startOrbot.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startOrbot.putExtra(OrbotRequiredDialogActivity.EXTRA_START_ORBOT, true);
+
Messenger messenger = new Messenger(
new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case OrbotRequiredDialogActivity.MESSAGE_ORBOT_STARTED: {
- asyncKeyUpdate(KeyserverSyncAdapterService.this,
- new CryptoInputParcel());
- break;
- }
- case OrbotRequiredDialogActivity.MESSAGE_ORBOT_IGNORE: {
- asyncKeyUpdate(KeyserverSyncAdapterService.this,
- new CryptoInputParcel(
- ParcelableProxy.getForNoProxy()));
+ startServiceWithUpdateAll();
break;
}
+ case OrbotRequiredDialogActivity.MESSAGE_ORBOT_IGNORE:
case OrbotRequiredDialogActivity.MESSAGE_DIALOG_CANCEL: {
- // just stop service
- stopSelf();
+ // not possible since we proceed to Orbot's Activity
+ // directly, by starting OrbotRequiredDialogActivity with
+ // EXTRA_START_ORBOT set to true
break;
}
}
@@ -138,13 +146,17 @@ public class KeyserverSyncAdapterService extends Service {
);
startOrbot.putExtra(OrbotRequiredDialogActivity.EXTRA_MESSENGER, messenger);
startActivity(startOrbot);
- break;
+ // since we return START_NOT_STICKY, we also postpone the sync as a backup in case
+ // the service is killed before OrbotRequiredDialogActivity can get back to us
+ postponeSync();
+ // if use START_REDELIVER_INTENT, we might annoy the user by repeatedly starting the
+ // Orbot Activity when our service is killed and restarted
+ return START_NOT_STICKY;
}
case ACTION_DISMISS_NOTIFICATION: {
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.cancel(Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT);
- stopSelf(startId);
- break;
+ return START_NOT_STICKY;
}
}
return START_NOT_STICKY;
@@ -167,10 +179,7 @@ public class KeyserverSyncAdapterService extends Service {
boolean isScreenOn = pm.isScreenOn();
if (!isScreenOn) {
- Intent serviceIntent = new Intent(KeyserverSyncAdapterService.this,
- KeyserverSyncAdapterService.class);
- serviceIntent.setAction(ACTION_UPDATE_ALL);
- startService(serviceIntent);
+ startServiceWithUpdateAll();
} else {
postponeSync();
}
@@ -188,16 +197,24 @@ public class KeyserverSyncAdapterService extends Service {
return new KeyserverSyncAdapter().getSyncAdapterBinder();
}
- private void handleUpdateResult(ImportKeyResult result) {
+ /**
+ * Since we're returning START_REDELIVER_INTENT in onStartCommand, we need to remember to call
+ * stopSelf(int) to prevent the Intent from being redelivered if our work is already done
+ *
+ * @param result result of keyserver sync
+ * @param startId startId provided to the onStartCommand call which resulted in this sync
+ */
+ private void handleUpdateResult(ImportKeyResult result, final int startId) {
if (result.isPending()) {
+ Log.d(Constants.TAG, "Orbot required for sync but not running, attempting to start");
// result is pending due to Orbot not being started
// try to start it silently, if disabled show notifications
new OrbotHelper.SilentStartManager() {
@Override
protected void onOrbotStarted() {
// retry the update
- asyncKeyUpdate(KeyserverSyncAdapterService.this,
- new CryptoInputParcel());
+ startServiceWithUpdateAll();
+ stopSelf(startId); // startServiceWithUpdateAll will deliver a new Intent
}
@Override
@@ -207,16 +224,24 @@ public class KeyserverSyncAdapterService extends Service {
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT,
getOrbotNoification(KeyserverSyncAdapterService.this));
+ // further action on user interaction with notification, intent should not be
+ // redelivered, therefore:
+ stopSelf(startId);
}
}.startOrbotAndListen(this, false);
+ // if we're killed before we get a response from Orbot, we need the intent to be
+ // redelivered, so no stopSelf(int) here
} else if (isUpdateCancelled()) {
Log.d(Constants.TAG, "Keyserver sync cancelled, postponing by" + SYNC_POSTPONE_TIME
+ "ms");
postponeSync();
+ // postponeSync creates a new intent, so we don't need this to be redelivered
+ stopSelf(startId);
} else {
Log.d(Constants.TAG, "Keyserver sync completed: Updated: " + result.mUpdatedKeys
+ " Failed: " + result.mBadKeys);
- stopSelf();
+ // key sync completed successfully, we can stop
+ stopSelf(startId);
}
}
@@ -234,12 +259,12 @@ public class KeyserverSyncAdapterService extends Service {
}
private void asyncKeyUpdate(final Context context,
- final CryptoInputParcel cryptoInputParcel) {
+ final CryptoInputParcel cryptoInputParcel, final int startId) {
new Thread(new Runnable() {
@Override
public void run() {
ImportKeyResult result = updateKeysFromKeyserver(context, cryptoInputParcel);
- handleUpdateResult(result);
+ handleUpdateResult(result, startId);
}
}).start();
}
@@ -278,7 +303,6 @@ public class KeyserverSyncAdapterService extends Service {
);
}
-
/**
* will perform a staggered update of user's keys using delays to ensure new Tor circuits, as
* performed by parcimonie. Relevant issue and method at:
@@ -290,17 +314,31 @@ public class KeyserverSyncAdapterService extends Service {
CryptoInputParcel cryptoInputParcel) {
Log.d(Constants.TAG, "Starting staggered update");
// final int WEEK_IN_SECONDS = (int) TimeUnit.DAYS.toSeconds(7);
+ // we are limiting our randomness to ORBOT_CIRCUIT_TIMEOUT_SECONDS for now
final int WEEK_IN_SECONDS = 0;
+
ImportOperation.KeyImportAccumulator accumulator
= new ImportOperation.KeyImportAccumulator(keyList.size(), null);
+
+ // so that the first key can be updated without waiting. This is so that there isn't a
+ // large gap between a "Start Orbot" notification and the next key update
+ boolean first = true;
+
for (ParcelableKeyRing keyRing : keyList) {
int waitTime;
int staggeredTime = new Random().nextInt(1 + 2 * (WEEK_IN_SECONDS / keyList.size()));
- if (staggeredTime >= ORBOT_CIRCUIT_TIMEOUT) {
+ if (staggeredTime >= ORBOT_CIRCUIT_TIMEOUT_SECONDS) {
waitTime = staggeredTime;
} else {
- waitTime = ORBOT_CIRCUIT_TIMEOUT + new Random().nextInt(ORBOT_CIRCUIT_TIMEOUT);
+ waitTime = ORBOT_CIRCUIT_TIMEOUT_SECONDS
+ + new Random().nextInt(1 + ORBOT_CIRCUIT_TIMEOUT_SECONDS);
+ }
+
+ if (first) {
+ waitTime = 0;
+ first = false;
}
+
Log.d(Constants.TAG, "Updating key with fingerprint " + keyRing.mExpectedFingerprint +
" with a wait time of " + waitTime + "s");
try {
@@ -362,13 +400,15 @@ public class KeyserverSyncAdapterService extends Service {
);
ArrayList<Long> ignoreMasterKeyIds = new ArrayList<>();
- while (updatedKeysCursor.moveToNext()) {
+ while (updatedKeysCursor != null && updatedKeysCursor.moveToNext()) {
long masterKeyId = updatedKeysCursor.getLong(INDEX_UPDATED_KEYS_MASTER_KEY_ID);
Log.d(Constants.TAG, "Keyserver sync: Ignoring {" + masterKeyId + "} last updated at {"
+ updatedKeysCursor.getLong(INDEX_LAST_UPDATED) + "}s");
ignoreMasterKeyIds.add(masterKeyId);
}
- updatedKeysCursor.close();
+ if (updatedKeysCursor != null) {
+ updatedKeysCursor.close();
+ }
// 2. Make a list of public keys which should be updated
final int INDEX_MASTER_KEY_ID = 0;
@@ -413,7 +453,7 @@ public class KeyserverSyncAdapterService extends Service {
/**
* will cancel an update already in progress. We send an Intent to cancel it instead of simply
- * modifying a static variable sync the service is running in a process that is different from
+ * modifying a static variable since the service is running in a process that is different from
* the default application process where the UI code runs.
*
* @param context used to send an Intent to the service requesting cancellation.
@@ -491,6 +531,12 @@ public class KeyserverSyncAdapterService extends Service {
}
}
+ private void startServiceWithUpdateAll() {
+ Intent serviceIntent = new Intent(this, KeyserverSyncAdapterService.class);
+ serviceIntent.setAction(ACTION_UPDATE_ALL);
+ this.startService(serviceIntent);
+ }
+
// from de.azapps.mirakel.helper.Helpers from https://github.com/MirakelX/mirakel-android
private Bitmap getBitmap(int resId, Context context) {
int mLargeIconWidth = (int) context.getResources().getDimension(
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java
index 0afb942b5..50dbc9a8b 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java
@@ -60,6 +60,9 @@ public class EncryptTextActivity extends EncryptActivity {
extras = new Bundle();
}
+ String textData = extras.getString(EXTRA_TEXT);
+ boolean returnProcessText = false;
+
// When sending to OpenKeychain Encrypt via share menu
if (Intent.ACTION_SEND.equals(action) && type != null) {
Log.logDebugBundle(extras, "extras");
@@ -95,12 +98,33 @@ public class EncryptTextActivity extends EncryptActivity {
}
// handle like normal text encryption, override action and extras to later
// executeServiceMethod ACTION_ENCRYPT_TEXT in main actions
- extras.putString(EXTRA_TEXT, sharedText);
+ textData = sharedText;
}
}
- String textData = extras.getString(EXTRA_TEXT);
+ // Android 6, PROCESS_TEXT Intent
+ if (Intent.ACTION_PROCESS_TEXT.equals(action) && type != null) {
+
+ String sharedText = null;
+ if (extras.containsKey(Intent.EXTRA_PROCESS_TEXT)) {
+ sharedText = extras.getString(Intent.EXTRA_PROCESS_TEXT);
+ returnProcessText = true;
+ } else if (extras.containsKey(Intent.EXTRA_PROCESS_TEXT_READONLY)) {
+ sharedText = extras.getString(Intent.EXTRA_PROCESS_TEXT_READONLY);
+ }
+
+ if (sharedText != null) {
+ if (sharedText.length() > Constants.TEXT_LENGTH_LIMIT) {
+ sharedText = sharedText.substring(0, Constants.TEXT_LENGTH_LIMIT);
+ Notify.create(this, R.string.snack_shared_text_too_long, Style.WARN).show();
+ }
+ // handle like normal text encryption, override action and extras to later
+ // executeServiceMethod ACTION_ENCRYPT_TEXT in main actions
+ textData = sharedText;
+ }
+ }
+
if (textData == null) {
textData = "";
}
@@ -108,7 +132,7 @@ public class EncryptTextActivity extends EncryptActivity {
if (savedInstanceState == null) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- EncryptTextFragment encryptFragment = EncryptTextFragment.newInstance(textData);
+ EncryptTextFragment encryptFragment = EncryptTextFragment.newInstance(textData, returnProcessText);
transaction.replace(R.id.encrypt_text_container, encryptFragment);
transaction.commit();
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextFragment.java
index 4ce241c02..10d88253d 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextFragment.java
@@ -56,8 +56,10 @@ public class EncryptTextFragment
public static final String ARG_TEXT = "text";
public static final String ARG_USE_COMPRESSION = "use_compression";
+ public static final String ARG_RETURN_PROCESS_TEXT = "return_process_text";
private boolean mShareAfterEncrypt;
+ private boolean mReturnProcessTextAfterEncrypt;
private boolean mUseCompression;
private boolean mHiddenRecipients = false;
@@ -66,11 +68,12 @@ public class EncryptTextFragment
/**
* Creates new instance of this fragment
*/
- public static EncryptTextFragment newInstance(String text) {
+ public static EncryptTextFragment newInstance(String text, boolean returnProcessTextAfterEncrypt) {
EncryptTextFragment frag = new EncryptTextFragment();
Bundle args = new Bundle();
args.putString(ARG_TEXT, text);
+ args.putBoolean(ARG_RETURN_PROCESS_TEXT, returnProcessTextAfterEncrypt);
frag.setArguments(args);
return frag;
@@ -128,6 +131,7 @@ public class EncryptTextFragment
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
mMessage = getArguments().getString(ARG_TEXT);
+ mReturnProcessTextAfterEncrypt = getArguments().getBoolean(ARG_RETURN_PROCESS_TEXT, false);
}
Preferences prefs = Preferences.getPreferences(getActivity());
@@ -151,6 +155,12 @@ public class EncryptTextFragment
inflater.inflate(R.menu.encrypt_text_fragment, menu);
menu.findItem(R.id.check_enable_compression).setChecked(mUseCompression);
+
+ if (mReturnProcessTextAfterEncrypt) {
+ menu.findItem(R.id.encrypt_paste).setVisible(true);
+ menu.findItem(R.id.encrypt_copy).setVisible(false);
+ menu.findItem(R.id.encrypt_share).setVisible(false);
+ }
}
@Override
@@ -177,6 +187,11 @@ public class EncryptTextFragment
cryptoOperation(new CryptoInputParcel(new Date()));
break;
}
+ case R.id.encrypt_paste: {
+ hideKeyboard();
+ cryptoOperation(new CryptoInputParcel(new Date()));
+ break;
+ }
default: {
return super.onOptionsItemSelected(item);
}
@@ -328,6 +343,11 @@ public class EncryptTextFragment
// Share encrypted message/file
startActivity(Intent.createChooser(createSendIntent(result.getResultBytes()),
getString(R.string.title_share_message)));
+ } else if (mReturnProcessTextAfterEncrypt) {
+ Intent resultIntent = new Intent();
+ resultIntent.putExtra(Intent.EXTRA_PROCESS_TEXT, new String(result.getResultBytes()));
+ getActivity().setResult(Activity.RESULT_OK, resultIntent);
+ getActivity().finish();
} else {
// Copy to clipboard
copyToClipboard(result);
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeCaptureActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeCaptureActivity.java
index 6172c8c8e..bf024cb5b 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeCaptureActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeCaptureActivity.java
@@ -1,23 +1,31 @@
/*
* Copyright (C) 2015 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
+ * 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.
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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.
*
- * 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.
+ * 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;
+import android.Manifest;
+import android.app.Activity;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
+import android.support.v4.content.ContextCompat;
import android.view.KeyEvent;
import com.journeyapps.barcodescanner.CaptureManager;
@@ -29,6 +37,8 @@ public class QrCodeCaptureActivity extends FragmentActivity {
private CaptureManager capture;
private CompoundBarcodeView barcodeScannerView;
+ public static final int MY_PERMISSIONS_REQUEST_CAMERA = 42;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -38,33 +48,87 @@ public class QrCodeCaptureActivity extends FragmentActivity {
barcodeScannerView = (CompoundBarcodeView) findViewById(R.id.zxing_barcode_scanner);
barcodeScannerView.setStatusText(getString(R.string.import_qr_code_text));
+ if (savedInstanceState != null) {
+ init(barcodeScannerView, getIntent(), savedInstanceState);
+ }
+
+ // check Android 6 permission
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
+ == PackageManager.PERMISSION_GRANTED) {
+ init(barcodeScannerView, getIntent(), null);
+ } else {
+
+// // Should we show an explanation?
+// if (ActivityCompat.shouldShowRequestPermissionRationale(this,
+// Manifest.permission.CAMERA)) {
+//
+// // Show an explanation to the user *asynchronously* -- don't block
+// // this thread waiting for the user's response! After the user
+// // sees the explanation, try again to request the permission.
+//
+// } else {
+
+ ActivityCompat.requestPermissions(this,
+ new String[]{Manifest.permission.CAMERA},
+ MY_PERMISSIONS_REQUEST_CAMERA);
+
+// }
+ }
+ }
+
+ private void init(CompoundBarcodeView barcodeScannerView, Intent intent, Bundle savedInstanceState) {
capture = new CaptureManager(this, barcodeScannerView);
- capture.initializeFromIntent(getIntent(), savedInstanceState);
+ capture.initializeFromIntent(intent, savedInstanceState);
capture.decode();
}
@Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[],
+ @NonNull int[] grantResults) {
+ switch (requestCode) {
+ case MY_PERMISSIONS_REQUEST_CAMERA: {
+ if (grantResults.length > 0
+ && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ // permission was granted
+ init(barcodeScannerView, getIntent(), null);
+ } else {
+ setResult(Activity.RESULT_CANCELED);
+ finish();
+ }
+ }
+ }
+ }
+
+ @Override
protected void onResume() {
super.onResume();
- capture.onResume();
+ if (capture != null) {
+ capture.onResume();
+ }
}
@Override
protected void onPause() {
super.onPause();
- capture.onPause();
+ if (capture != null) {
+ capture.onPause();
+ }
}
@Override
protected void onDestroy() {
super.onDestroy();
- capture.onDestroy();
+ if (capture != null) {
+ capture.onDestroy();
+ }
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
- capture.onSaveInstanceState(outState);
+ if (capture != null) {
+ capture.onSaveInstanceState(outState);
+ }
}
@Override
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java
index cbc7b88bf..0184527b7 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java
@@ -38,6 +38,7 @@ import android.os.Handler;
import android.provider.ContactsContract;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
+import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentManager;
@@ -869,7 +870,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements
mActionEncryptFile.setVisibility(View.INVISIBLE);
mActionEncryptText.setVisibility(View.INVISIBLE);
mActionNfc.setVisibility(View.INVISIBLE);
- mFab.setVisibility(View.GONE);
+ hideFab();
mQrCodeLayout.setVisibility(View.GONE);
} else if (mIsExpired) {
if (mIsSecret) {
@@ -885,7 +886,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements
mActionEncryptFile.setVisibility(View.INVISIBLE);
mActionEncryptText.setVisibility(View.INVISIBLE);
mActionNfc.setVisibility(View.INVISIBLE);
- mFab.setVisibility(View.GONE);
+ hideFab();
mQrCodeLayout.setVisibility(View.GONE);
} else if (mIsSecret) {
mStatusText.setText(R.string.view_key_my_key);
@@ -927,7 +928,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements
} else {
mActionNfc.setVisibility(View.GONE);
}
- mFab.setVisibility(View.VISIBLE);
+ showFab();
// noinspection deprecation (no getDrawable with theme at current minApi level 15!)
mFab.setImageDrawable(getResources().getDrawable(R.drawable.ic_repeat_white_24dp));
} else {
@@ -944,7 +945,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements
color = getResources().getColor(R.color.key_flag_green);
photoTask.execute(mMasterKeyId);
- mFab.setVisibility(View.GONE);
+ hideFab();
} else {
mStatusText.setText(R.string.view_key_unverified);
mStatusImage.setVisibility(View.VISIBLE);
@@ -952,7 +953,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements
State.UNVERIFIED, R.color.icons, true);
color = getResources().getColor(R.color.key_flag_orange);
- mFab.setVisibility(View.VISIBLE);
+ showFab();
}
}
@@ -982,6 +983,28 @@ public class ViewKeyActivity extends BaseNfcActivity implements
}
}
+ /**
+ * Helper to show Fab, from http://stackoverflow.com/a/31047038
+ */
+ private void showFab() {
+ CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) mFab.getLayoutParams();
+ p.setBehavior(new FloatingActionButton.Behavior());
+ p.setAnchorId(R.id.app_bar_layout);
+ mFab.setLayoutParams(p);
+ mFab.setVisibility(View.VISIBLE);
+ }
+
+ /**
+ * Helper to hide Fab, from http://stackoverflow.com/a/31047038
+ */
+ private void hideFab() {
+ CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) mFab.getLayoutParams();
+ p.setBehavior(null); //should disable default animations
+ p.setAnchorId(View.NO_ID); //should let you set visibility
+ mFab.setLayoutParams(p);
+ mFab.setVisibility(View.GONE);
+ }
+
@Override
public void onLoaderReset(Loader<Cursor> loader) {
diff --git a/OpenKeychain/src/main/res/drawable-hdpi/ic_action_encrypt_paste_24dp.png b/OpenKeychain/src/main/res/drawable-hdpi/ic_action_encrypt_paste_24dp.png
new file mode 100644
index 000000000..356cfbe43
--- /dev/null
+++ b/OpenKeychain/src/main/res/drawable-hdpi/ic_action_encrypt_paste_24dp.png
Binary files differ
diff --git a/OpenKeychain/src/main/res/drawable-mdpi/ic_action_encrypt_paste_24dp.png b/OpenKeychain/src/main/res/drawable-mdpi/ic_action_encrypt_paste_24dp.png
new file mode 100644
index 000000000..a546e152b
--- /dev/null
+++ b/OpenKeychain/src/main/res/drawable-mdpi/ic_action_encrypt_paste_24dp.png
Binary files differ
diff --git a/OpenKeychain/src/main/res/drawable-xhdpi/ic_action_encrypt_paste_24dp.png b/OpenKeychain/src/main/res/drawable-xhdpi/ic_action_encrypt_paste_24dp.png
new file mode 100644
index 000000000..ed7fdb732
--- /dev/null
+++ b/OpenKeychain/src/main/res/drawable-xhdpi/ic_action_encrypt_paste_24dp.png
Binary files differ
diff --git a/OpenKeychain/src/main/res/drawable-xhdpi/status_signature_expired_cutout_96dp.png b/OpenKeychain/src/main/res/drawable-xhdpi/status_signature_expired_cutout_96dp.png
index e69de29bb..568b48c43 100644
--- a/OpenKeychain/src/main/res/drawable-xhdpi/status_signature_expired_cutout_96dp.png
+++ b/OpenKeychain/src/main/res/drawable-xhdpi/status_signature_expired_cutout_96dp.png
Binary files differ
diff --git a/OpenKeychain/src/main/res/drawable-xxhdpi/ic_action_encrypt_paste_24dp.png b/OpenKeychain/src/main/res/drawable-xxhdpi/ic_action_encrypt_paste_24dp.png
new file mode 100644
index 000000000..50987bdd6
--- /dev/null
+++ b/OpenKeychain/src/main/res/drawable-xxhdpi/ic_action_encrypt_paste_24dp.png
Binary files differ
diff --git a/OpenKeychain/src/main/res/drawable-xxxhdpi/ic_action_encrypt_paste_24dp.png b/OpenKeychain/src/main/res/drawable-xxxhdpi/ic_action_encrypt_paste_24dp.png
new file mode 100644
index 000000000..11ad7e219
--- /dev/null
+++ b/OpenKeychain/src/main/res/drawable-xxxhdpi/ic_action_encrypt_paste_24dp.png
Binary files differ
diff --git a/OpenKeychain/src/main/res/menu/encrypt_text_fragment.xml b/OpenKeychain/src/main/res/menu/encrypt_text_fragment.xml
index 80b78457d..4d3d53870 100644
--- a/OpenKeychain/src/main/res/menu/encrypt_text_fragment.xml
+++ b/OpenKeychain/src/main/res/menu/encrypt_text_fragment.xml
@@ -3,6 +3,14 @@
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
+ android:id="@+id/encrypt_paste"
+ android:title="@string/btn_paste_encrypted_signed"
+ android:icon="@drawable/ic_action_encrypt_paste_24dp"
+ android:orderInCategory="1"
+ android:visible="false"
+ app:showAsAction="ifRoom" />
+
+ <item
android:id="@+id/encrypt_copy"
android:title="@string/btn_copy_encrypted_signed"
android:icon="@drawable/ic_action_encrypt_copy_24dp"
diff --git a/OpenKeychain/src/main/res/values-v23/themes.xml b/OpenKeychain/src/main/res/values-v23/themes.xml
new file mode 100644
index 000000000..29bd762c0
--- /dev/null
+++ b/OpenKeychain/src/main/res/values-v23/themes.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <!-- see http://stackoverflow.com/questions/32169303/activity-did-not-call-finish-api-23 -->
+ <style name="Theme.Keychain.Transparent" parent="@android:style/Theme.Translucent.NoTitleBar" />
+
+</resources>
diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml
index 486176fc2..2f7c703ad 100644
--- a/OpenKeychain/src/main/res/values/strings.xml
+++ b/OpenKeychain/src/main/res/values/strings.xml
@@ -88,6 +88,7 @@
<string name="btn_match_phrases">"Phrases match"</string>
<string name="btn_share_encrypted_signed">"Encrypt/sign and share text"</string>
<string name="btn_copy_encrypted_signed">"Encrypt/sign and copy text"</string>
+ <string name="btn_paste_encrypted_signed">"Encrypt/sign and paste text"</string>
<string name="btn_view_cert_key">"View certification key"</string>
<string name="btn_create_key">"Create key"</string>
<string name="btn_add_files">"Add file(s)"</string>
diff --git a/OpenKeychain/src/main/res/values/themes.xml b/OpenKeychain/src/main/res/values/themes.xml
index 38cf8a3db..fc6ae3846 100644
--- a/OpenKeychain/src/main/res/values/themes.xml
+++ b/OpenKeychain/src/main/res/values/themes.xml
@@ -85,11 +85,9 @@
<item name="alertDialogTheme">@style/Theme.Keychain.Dark.Dialog.Alert</item>
</style>
- <style name="Theme.Keychain.Light" parent="Base.Theme.Keychain.Light">
- </style>
+ <style name="Theme.Keychain.Light" parent="Base.Theme.Keychain.Light"></style>
- <style name="Theme.Keychain.Dark" parent="Base.Theme.Keychain.Dark">
- </style>
+ <style name="Theme.Keychain.Dark" parent="Base.Theme.Keychain.Dark"></style>
<!-- http://android-developers.blogspot.de/2014/10/appcompat-v21-material-design-for-pre.html -->
<style name="Widget.Keychain.SearchView" parent="Widget.AppCompat.SearchView">
@@ -134,4 +132,6 @@
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
+
+ <style name="Theme.Keychain.Transparent" parent="@android:style/Theme.NoDisplay" />
</resources>