mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-30 12:32:17 -05:00
handle EXTRA_TEXT in decrypt activity
This commit is contained in:
parent
d1ceb73eb0
commit
ae56f4f900
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.ui;
|
package org.sufficientlysecure.keychain.ui;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@ -31,6 +33,7 @@ import android.widget.Toast;
|
|||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.intents.OpenKeychainIntents;
|
import org.sufficientlysecure.keychain.intents.OpenKeychainIntents;
|
||||||
|
import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider;
|
||||||
import org.sufficientlysecure.keychain.ui.base.BaseActivity;
|
import org.sufficientlysecure.keychain.ui.base.BaseActivity;
|
||||||
|
|
||||||
|
|
||||||
@ -79,31 +82,57 @@ public class DecryptActivity extends BaseActivity {
|
|||||||
|
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
|
|
||||||
// TODO handle ACTION_DECRYPT_FROM_CLIPBOARD
|
try {
|
||||||
switch (action) {
|
|
||||||
case Intent.ACTION_SEND: {
|
// TODO handle ACTION_DECRYPT_FROM_CLIPBOARD
|
||||||
// When sending to Keychain Decrypt via share menu
|
switch (action) {
|
||||||
// Binary via content provider (could also be files)
|
case Intent.ACTION_SEND: {
|
||||||
// override uri to get stream from send
|
// When sending to Keychain Decrypt via share menu
|
||||||
action = ACTION_DECRYPT_DATA;
|
// Binary via content provider (could also be files)
|
||||||
uris.add(intent.<Uri>getParcelableExtra(Intent.EXTRA_STREAM));
|
// override uri to get stream from send
|
||||||
break;
|
action = ACTION_DECRYPT_DATA;
|
||||||
|
|
||||||
|
if (intent.hasExtra(Intent.EXTRA_STREAM)) {
|
||||||
|
uris.add(intent.<Uri>getParcelableExtra(Intent.EXTRA_STREAM));
|
||||||
|
} else if (intent.hasExtra(Intent.EXTRA_TEXT)) {
|
||||||
|
String text = intent.getStringExtra(Intent.EXTRA_TEXT);
|
||||||
|
Uri uri = readToTempFile(text);
|
||||||
|
uris.add(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Intent.ACTION_SEND_MULTIPLE: {
|
||||||
|
action = ACTION_DECRYPT_DATA;
|
||||||
|
|
||||||
|
if (intent.hasExtra(Intent.EXTRA_STREAM)) {
|
||||||
|
uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
||||||
|
} else if (intent.hasExtra(Intent.EXTRA_TEXT)) {
|
||||||
|
for (String text : intent.getStringArrayListExtra(Intent.EXTRA_TEXT)) {
|
||||||
|
Uri uri = readToTempFile(text);
|
||||||
|
uris.add(uri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Intent.ACTION_VIEW:
|
||||||
|
// Android's Action when opening file associated to Keychain (see AndroidManifest.xml)
|
||||||
|
action = ACTION_DECRYPT_DATA;
|
||||||
|
|
||||||
|
// fallthrough
|
||||||
|
default:
|
||||||
|
uris.add(intent.getData());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case Intent.ACTION_SEND_MULTIPLE: {
|
|
||||||
action = ACTION_DECRYPT_DATA;
|
|
||||||
uris.addAll(intent.<Uri>getParcelableArrayListExtra(Intent.EXTRA_STREAM));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case Intent.ACTION_VIEW:
|
|
||||||
// Android's Action when opening file associated to Keychain (see AndroidManifest.xml)
|
|
||||||
action = ACTION_DECRYPT_DATA;
|
|
||||||
|
|
||||||
// fallthrough
|
|
||||||
default:
|
|
||||||
uris.add(intent.getData());
|
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
Toast.makeText(this, R.string.error_reading_text, Toast.LENGTH_LONG).show();
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ACTION_DECRYPT_DATA.equals(action)) {
|
if (ACTION_DECRYPT_DATA.equals(action)) {
|
||||||
@ -122,6 +151,14 @@ public class DecryptActivity extends BaseActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Uri readToTempFile(String text) throws IOException {
|
||||||
|
Uri tempFile = TemporaryStorageProvider.createFile(this);
|
||||||
|
OutputStream outStream = getContentResolver().openOutputStream(tempFile);
|
||||||
|
outStream.write(text.getBytes());
|
||||||
|
outStream.close();
|
||||||
|
return tempFile;
|
||||||
|
}
|
||||||
|
|
||||||
public void displayInputFragment(boolean showOpenDialog) {
|
public void displayInputFragment(boolean showOpenDialog) {
|
||||||
DecryptFilesInputFragment frag = DecryptFilesInputFragment.newInstance(showOpenDialog);
|
DecryptFilesInputFragment frag = DecryptFilesInputFragment.newInstance(showOpenDialog);
|
||||||
|
|
||||||
|
@ -1331,7 +1331,8 @@
|
|||||||
<string name="snack_armor_off">"Output encoded as Binary."</string>
|
<string name="snack_armor_off">"Output encoded as Binary."</string>
|
||||||
<string name="snack_compression_on">"Compression <b>enabled</b>."</string>
|
<string name="snack_compression_on">"Compression <b>enabled</b>."</string>
|
||||||
<string name="snack_compression_off">"Compression <b>disabled</b>."</string>
|
<string name="snack_compression_off">"Compression <b>disabled</b>."</string>
|
||||||
<string name="error_loading_keys">Error loading keys!</string>
|
<string name="error_loading_keys">"Error loading keys!"</string>
|
||||||
<string name="error_empty_log">(error, empty log)</string>
|
<string name="error_empty_log">"(error, empty log)"</string>
|
||||||
|
<string name="error_reading_text">"Could not read input to decrypt!"</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user