API: Fix re-seletion of keys on default account

This commit is contained in:
Dominik Schürmann 2014-08-23 15:27:25 +02:00
parent 79c4d3ea49
commit 71657d993c
2 changed files with 16 additions and 9 deletions

View File

@ -23,6 +23,7 @@ import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.IBinder; import android.os.IBinder;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.text.TextUtils;
import org.openintents.openpgp.IOpenPgpService; import org.openintents.openpgp.IOpenPgpService;
import org.openintents.openpgp.OpenPgpMetadata; import org.openintents.openpgp.OpenPgpMetadata;
@ -185,7 +186,7 @@ public class OpenPgpService extends RemoteService {
} catch (PassphraseCacheService.KeyNotFoundException e) { } catch (PassphraseCacheService.KeyNotFoundException e) {
// secret key that is set for this account is deleted? // secret key that is set for this account is deleted?
// show account config again! // show account config again!
return getCreateAccountIntent(data, data.getStringExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME)); return getCreateAccountIntent(data, getAccountName(data));
} }
} }
if (passphrase == null) { if (passphrase == null) {
@ -564,6 +565,16 @@ public class OpenPgpService extends RemoteService {
return null; return null;
} }
private String getAccountName(Intent data) {
String accName = data.getStringExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME);
// if no account name is given use name "default"
if (TextUtils.isEmpty(accName)) {
accName = "default";
}
Log.d(Constants.TAG, "accName: " + accName);
return accName;
}
// TODO: multi-threading // TODO: multi-threading
private final IOpenPgpService.Stub mBinder = new IOpenPgpService.Stub() { private final IOpenPgpService.Stub mBinder = new IOpenPgpService.Stub() {
@ -574,12 +585,7 @@ public class OpenPgpService extends RemoteService {
return errorResult; return errorResult;
} }
String accName; String accName = getAccountName(data);
if (data.getStringExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME) != null) {
accName = data.getStringExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME);
} else {
accName = "default";
}
final AccountSettings accSettings = getAccSettings(accName); final AccountSettings accSettings = getAccSettings(accName);
if (accSettings == null) { if (accSettings == null) {
return getCreateAccountIntent(data, accName); return getCreateAccountIntent(data, accName);

View File

@ -27,6 +27,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature; import android.content.pm.Signature;
import android.net.Uri; import android.net.Uri;
import android.os.Binder; import android.os.Binder;
import android.text.TextUtils;
import org.openintents.openpgp.OpenPgpError; import org.openintents.openpgp.OpenPgpError;
import org.openintents.openpgp.util.OpenPgpApi; import org.openintents.openpgp.util.OpenPgpApi;
@ -160,7 +161,7 @@ public abstract class RemoteService extends Service {
*/ */
protected AccountSettings getAccSettings(String accountName) { protected AccountSettings getAccSettings(String accountName) {
String currentPkg = getCurrentCallingPackage(); String currentPkg = getCurrentCallingPackage();
Log.d(Constants.TAG, "accountName: " + accountName); Log.d(Constants.TAG, "getAccSettings accountName: "+ accountName);
Uri uri = KeychainContract.ApiAccounts.buildByPackageAndAccountUri(currentPkg, accountName); Uri uri = KeychainContract.ApiAccounts.buildByPackageAndAccountUri(currentPkg, accountName);
@ -171,7 +172,7 @@ public abstract class RemoteService extends Service {
protected Intent getCreateAccountIntent(Intent data, String accountName) { protected Intent getCreateAccountIntent(Intent data, String accountName) {
String packageName = getCurrentCallingPackage(); String packageName = getCurrentCallingPackage();
Log.d(Constants.TAG, "accountName: " + accountName); Log.d(Constants.TAG, "getCreateAccountIntent accountName: " + accountName);
Intent intent = new Intent(getBaseContext(), RemoteServiceActivity.class); Intent intent = new Intent(getBaseContext(), RemoteServiceActivity.class);
intent.setAction(RemoteServiceActivity.ACTION_CREATE_ACCOUNT); intent.setAction(RemoteServiceActivity.ACTION_CREATE_ACCOUNT);