PendingIntent to handle user input
This commit is contained in:
@@ -235,7 +235,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial
|
||||
|
||||
String action = intent.getAction();
|
||||
|
||||
// execute action from extra bundle
|
||||
// executeServiceMethod action from extra bundle
|
||||
if (ACTION_ENCRYPT_SIGN.equals(action)) {
|
||||
try {
|
||||
/* Input */
|
||||
|
||||
@@ -50,6 +50,8 @@ import org.sufficientlysecure.keychain.service.exception.WrongPassphraseExceptio
|
||||
import org.sufficientlysecure.keychain.util.InputData;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
@@ -308,8 +310,20 @@ public class OpenPgpService extends RemoteService {
|
||||
String passphrase = PassphraseCacheService.getCachedPassphrase(getContext(), appSettings.getKeyId());
|
||||
if (passphrase == null) {
|
||||
// TODO: we need to abort and return a passphrase Intent!
|
||||
|
||||
Intent intent = new Intent(getBaseContext(), RemoteServiceActivity.class);
|
||||
// TODO: setComponent really needed for security?
|
||||
// intent.setComponent(new ComponentName(Constants.PACKAGE_NAME,
|
||||
// "org.sufficientlysecure.keychain.service.remote.RemoteServiceActivity"));
|
||||
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.setAction(RemoteServiceActivity.ACTION_CACHE_PASSPHRASE);
|
||||
intent.putExtra(RemoteServiceActivity.EXTRA_SECRET_KEY_ID, appSettings.getKeyId());
|
||||
PendingIntent pi = PendingIntent.getActivity(getBaseContext(), 42, intent, 0);
|
||||
|
||||
|
||||
Bundle result = new Bundle();
|
||||
result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_USER_INTERACTION_REQUIRED);
|
||||
result.putParcelable(OpenPgpConstants.RESULT_INTENT, pi);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -328,19 +342,19 @@ public class OpenPgpService extends RemoteService {
|
||||
|
||||
is.close();
|
||||
os.close();
|
||||
} catch (IOException e) {
|
||||
Log.e(Constants.TAG, "Fail", e);
|
||||
// } catch (IOException e) {
|
||||
// Log.e(Constants.TAG, "Fail", e);
|
||||
} finally {
|
||||
try {
|
||||
// try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// try {
|
||||
os.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
}
|
||||
|
||||
Bundle result = new Bundle();
|
||||
@@ -516,27 +530,42 @@ public class OpenPgpService extends RemoteService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that params != null and API version fits
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
private Bundle validateParamsAndVersion(Bundle params) {
|
||||
if (params == null) {
|
||||
Bundle result = new Bundle();
|
||||
OpenPgpError error = new OpenPgpError(OpenPgpError.GENERIC_ERROR, "params Bundle required!");
|
||||
result.putParcelable(OpenPgpConstants.RESULT_ERRORS, error);
|
||||
result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_ERROR);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (params.getInt(OpenPgpConstants.PARAMS_API_VERSION) != OpenPgpConstants.API_VERSION) {
|
||||
// not compatible!
|
||||
Bundle result = new Bundle();
|
||||
OpenPgpError error = new OpenPgpError(OpenPgpError.INCOMPATIBLE_API_VERSIONS, "Incompatible API versions!");
|
||||
result.putParcelable(OpenPgpConstants.RESULT_ERRORS, error);
|
||||
result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_ERROR);
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private final IOpenPgpService.Stub mBinder = new IOpenPgpService.Stub() {
|
||||
|
||||
@Override
|
||||
public Bundle sign(Bundle params, final ParcelFileDescriptor input, final ParcelFileDescriptor output) {
|
||||
final AppSettings appSettings = getAppSettings();
|
||||
|
||||
if (params == null) {
|
||||
Bundle result = new Bundle();
|
||||
OpenPgpError error = new OpenPgpError(OpenPgpError.GENERIC_ERROR, "params Bundle required!");
|
||||
result.putParcelable(OpenPgpConstants.RESULT_ERRORS, error);
|
||||
result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_ERROR);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (params.getInt(OpenPgpConstants.PARAMS_API_VERSION) != OpenPgpConstants.API_VERSION) {
|
||||
// not compatible!
|
||||
Bundle result = new Bundle();
|
||||
OpenPgpError error = new OpenPgpError(OpenPgpError.INCOMPATIBLE_API_VERSIONS, "Incompatible API versions!");
|
||||
result.putParcelable(OpenPgpConstants.RESULT_ERRORS, error);
|
||||
result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_ERROR);
|
||||
return result;
|
||||
Bundle errorResult = validateParamsAndVersion(params);
|
||||
if (errorResult != null) {
|
||||
return errorResult;
|
||||
}
|
||||
|
||||
// Runnable r = new Runnable() {
|
||||
|
||||
@@ -86,15 +86,15 @@ public class RemoteServiceActivity extends ActionBarActivity {
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
|
||||
if (!finishHandled) {
|
||||
Message msg = Message.obtain();
|
||||
msg.arg1 = RemoteService.RegisterActivityCallback.CANCEL;
|
||||
try {
|
||||
mMessenger.send(msg);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(Constants.TAG, "CryptoServiceActivity", e);
|
||||
}
|
||||
}
|
||||
// if (!finishHandled) {
|
||||
// Message msg = Message.obtain();
|
||||
// msg.arg1 = RemoteService.RegisterActivityCallback.CANCEL;
|
||||
// try {
|
||||
// mMessenger.send(msg);
|
||||
// } catch (RemoteException e) {
|
||||
// Log.e(Constants.TAG, "CryptoServiceActivity", e);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
protected void handleActions(Intent intent, Bundle savedInstanceState) {
|
||||
@@ -237,7 +237,7 @@ public class RemoteServiceActivity extends ActionBarActivity {
|
||||
|
||||
Message msg = Message.obtain();
|
||||
msg.arg1 = OpenPgpService.SelectPubKeysActivityCallback.CANCEL;
|
||||
;
|
||||
|
||||
try {
|
||||
mMessenger.send(msg);
|
||||
} catch (RemoteException e) {
|
||||
@@ -313,25 +313,31 @@ public class RemoteServiceActivity extends ActionBarActivity {
|
||||
@Override
|
||||
public void handleMessage(Message message) {
|
||||
if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
|
||||
Message msg = Message.obtain();
|
||||
msg.arg1 = OpenPgpService.PassphraseActivityCallback.OKAY;
|
||||
try {
|
||||
mMessenger.send(msg);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(Constants.TAG, "CryptoServiceActivity", e);
|
||||
}
|
||||
// Message msg = Message.obtain();
|
||||
// msg.arg1 = OpenPgpService.PassphraseActivityCallback.OKAY;
|
||||
// try {
|
||||
// mMessenger.send(msg);
|
||||
// } catch (RemoteException e) {
|
||||
// Log.e(Constants.TAG, "CryptoServiceActivity", e);
|
||||
// }
|
||||
|
||||
RemoteServiceActivity.this.setResult(RESULT_OK);
|
||||
RemoteServiceActivity.this.finish();
|
||||
} else {
|
||||
Message msg = Message.obtain();
|
||||
msg.arg1 = OpenPgpService.PassphraseActivityCallback.CANCEL;
|
||||
try {
|
||||
mMessenger.send(msg);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(Constants.TAG, "CryptoServiceActivity", e);
|
||||
}
|
||||
// Message msg = Message.obtain();
|
||||
// msg.arg1 = OpenPgpService.PassphraseActivityCallback.CANCEL;
|
||||
// try {
|
||||
// mMessenger.send(msg);
|
||||
// } catch (RemoteException e) {
|
||||
// Log.e(Constants.TAG, "CryptoServiceActivity", e);
|
||||
// }
|
||||
|
||||
RemoteServiceActivity.this.setResult(RESULT_CANCELED);
|
||||
RemoteServiceActivity.this.finish();
|
||||
}
|
||||
|
||||
finishHandled = true;
|
||||
finish();
|
||||
// finishHandled = true;
|
||||
// finish();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -346,7 +352,7 @@ public class RemoteServiceActivity extends ActionBarActivity {
|
||||
} catch (PgpGeneralException e) {
|
||||
Log.d(Constants.TAG, "No passphrase for this secret key, encrypt directly!");
|
||||
// send message to handler to start encryption directly
|
||||
returnHandler.sendEmptyMessage(PassphraseDialogFragment.MESSAGE_OKAY);
|
||||
// returnHandler.sendEmptyMessage(PassphraseDialogFragment.MESSAGE_OKAY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ public class DecryptActivity extends DrawerActivity {
|
||||
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
|
||||
if (sharedText != null) {
|
||||
// handle like normal text decryption, override action and extras to later
|
||||
// execute ACTION_DECRYPT in main actions
|
||||
// executeServiceMethod ACTION_DECRYPT in main actions
|
||||
extras.putString(EXTRA_TEXT, sharedText);
|
||||
action = ACTION_DECRYPT;
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ public class EncryptActivity extends DrawerActivity {
|
||||
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
|
||||
if (sharedText != null) {
|
||||
// handle like normal text encryption, override action and extras to later
|
||||
// execute ACTION_ENCRYPT in main actions
|
||||
// executeServiceMethod ACTION_ENCRYPT in main actions
|
||||
extras.putString(EXTRA_TEXT, sharedText);
|
||||
extras.putBoolean(EXTRA_ASCII_ARMOR, true);
|
||||
action = ACTION_ENCRYPT;
|
||||
|
||||
Reference in New Issue
Block a user