mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-15 21:35:05 -05:00
Return account creation intent if account does not exists in db
This commit is contained in:
parent
8c496d3393
commit
dc9fd12213
@ -160,6 +160,7 @@ public class KeychainContract {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Uri buildSecretKeyRingsByEmailsUri(String emails) {
|
public static Uri buildSecretKeyRingsByEmailsUri(String emails) {
|
||||||
|
// TODO: encoded?
|
||||||
return CONTENT_URI.buildUpon().appendPath(PATH_SECRET).appendPath(PATH_BY_EMAILS)
|
return CONTENT_URI.buildUpon().appendPath(PATH_SECRET).appendPath(PATH_BY_EMAILS)
|
||||||
.appendPath(emails).build();
|
.appendPath(emails).build();
|
||||||
}
|
}
|
||||||
@ -263,16 +264,12 @@ public class KeychainContract {
|
|||||||
/**
|
/**
|
||||||
* Use if multiple items get returned
|
* Use if multiple items get returned
|
||||||
*/
|
*/
|
||||||
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.api.app";
|
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.api_apps";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use if a single item is returned
|
* Use if a single item is returned
|
||||||
*/
|
*/
|
||||||
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.api.apps";
|
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.api_app";
|
||||||
|
|
||||||
// public static Uri buildIdUri(String rowId) {
|
|
||||||
// return CONTENT_URI.buildUpon().appendPath(rowId).build();
|
|
||||||
// }
|
|
||||||
|
|
||||||
public static Uri buildByPackageNameUri(String packageName) {
|
public static Uri buildByPackageNameUri(String packageName) {
|
||||||
return CONTENT_URI.buildUpon().appendEncodedPath(packageName).build();
|
return CONTENT_URI.buildUpon().appendEncodedPath(packageName).build();
|
||||||
@ -286,22 +283,12 @@ public class KeychainContract {
|
|||||||
/**
|
/**
|
||||||
* Use if multiple items get returned
|
* Use if multiple items get returned
|
||||||
*/
|
*/
|
||||||
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.api.acoounts";
|
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.api_app.accounts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use if a single item is returned
|
* Use if a single item is returned
|
||||||
*/
|
*/
|
||||||
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.api.account";
|
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.api_app.account";
|
||||||
|
|
||||||
// public static Uri buildUri(String rowIdApp) {
|
|
||||||
// return CONTENT_URI.buildUpon().appendPath(rowIdApp).appendPath(PATH_ACCOUNTS)
|
|
||||||
// .build();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public static Uri buildIdUri(String rowIdApp, String rowId) {
|
|
||||||
// return CONTENT_URI.buildUpon().appendPath(rowIdApp).appendPath(PATH_ACCOUNTS)
|
|
||||||
// .appendPath(rowId).build();
|
|
||||||
// }
|
|
||||||
|
|
||||||
public static Uri buildBaseUri(String packageName) {
|
public static Uri buildBaseUri(String packageName) {
|
||||||
return CONTENT_URI.buildUpon().appendEncodedPath(packageName).appendPath(PATH_ACCOUNTS)
|
return CONTENT_URI.buildUpon().appendEncodedPath(packageName).appendPath(PATH_ACCOUNTS)
|
||||||
|
@ -27,7 +27,6 @@ import android.database.sqlite.SQLiteDatabase;
|
|||||||
import android.database.sqlite.SQLiteQueryBuilder;
|
import android.database.sqlite.SQLiteQueryBuilder;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.BaseColumns;
|
import android.provider.BaseColumns;
|
||||||
import android.support.v4.database.DatabaseUtilsCompat;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
@ -243,10 +242,10 @@ public class KeychainProvider extends ContentProvider {
|
|||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* api_apps
|
* api_apps
|
||||||
* api_apps/_
|
* api_apps/_ (package name)
|
||||||
*
|
*
|
||||||
* api_apps/_/accounts
|
* api_apps/_/accounts
|
||||||
* api_apps/_/accounts/_
|
* api_apps/_/accounts/_ (account name)
|
||||||
* </pre>
|
* </pre>
|
||||||
*/
|
*/
|
||||||
matcher.addURI(authority, KeychainContract.BASE_API_APPS, API_APPS);
|
matcher.addURI(authority, KeychainContract.BASE_API_APPS, API_APPS);
|
||||||
|
@ -440,6 +440,9 @@ public class OpenPgpService extends RemoteService {
|
|||||||
accName = "default";
|
accName = "default";
|
||||||
}
|
}
|
||||||
final AccountSettings accSettings = getAccSettings(accName);
|
final AccountSettings accSettings = getAccSettings(accName);
|
||||||
|
if (accSettings == null) {
|
||||||
|
return getCreateAccountIntent(data, accName);
|
||||||
|
}
|
||||||
|
|
||||||
String action = data.getAction();
|
String action = data.getAction();
|
||||||
if (OpenPgpApi.ACTION_SIGN.equals(action)) {
|
if (OpenPgpApi.ACTION_SIGN.equals(action)) {
|
||||||
|
@ -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 org.openintents.openpgp.OpenPgpError;
|
import org.openintents.openpgp.OpenPgpError;
|
||||||
import org.openintents.openpgp.util.OpenPgpApi;
|
import org.openintents.openpgp.util.OpenPgpApi;
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
@ -48,7 +49,6 @@ public abstract class RemoteService extends Service {
|
|||||||
private static final int PRIVATE_REQUEST_CODE_REGISTER = 651;
|
private static final int PRIVATE_REQUEST_CODE_REGISTER = 651;
|
||||||
private static final int PRIVATE_REQUEST_CODE_ERROR = 652;
|
private static final int PRIVATE_REQUEST_CODE_ERROR = 652;
|
||||||
|
|
||||||
|
|
||||||
public Context getContext() {
|
public Context getContext() {
|
||||||
return mContext;
|
return mContext;
|
||||||
}
|
}
|
||||||
@ -56,13 +56,9 @@ public abstract class RemoteService extends Service {
|
|||||||
protected Intent isAllowed(Intent data) {
|
protected Intent isAllowed(Intent data) {
|
||||||
try {
|
try {
|
||||||
if (isCallerAllowed(false)) {
|
if (isCallerAllowed(false)) {
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
String[] callingPackages = getPackageManager().getPackagesForUid(
|
String packageName = getCurrentCallingPackage();
|
||||||
Binder.getCallingUid());
|
|
||||||
// TODO: currently simply uses first entry
|
|
||||||
String packageName = callingPackages[0];
|
|
||||||
|
|
||||||
byte[] packageSignature;
|
byte[] packageSignature;
|
||||||
try {
|
try {
|
||||||
@ -126,27 +122,56 @@ public abstract class RemoteService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves AppSettings from database for the application calling this remote service
|
* Returns package name associated with the UID, which is assigned to the process that sent you the
|
||||||
|
* current transaction that is being processed :)
|
||||||
|
*
|
||||||
|
* @return package name
|
||||||
|
*/
|
||||||
|
private String getCurrentCallingPackage() {
|
||||||
|
// TODO:
|
||||||
|
// callingPackages contains more than one entry when sharedUserId has been used...
|
||||||
|
String[] callingPackages = getPackageManager().getPackagesForUid(Binder.getCallingUid());
|
||||||
|
String currentPkg = callingPackages[0];
|
||||||
|
Log.d(Constants.TAG, "currentPkg: " + currentPkg);
|
||||||
|
|
||||||
|
return currentPkg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves AccountSettings from database for the application calling this remote service
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected AccountSettings getAccSettings(String accountName) {
|
protected AccountSettings getAccSettings(String accountName) {
|
||||||
String[] callingPackages = getPackageManager().getPackagesForUid(Binder.getCallingUid());
|
String currentPkg = getCurrentCallingPackage();
|
||||||
|
Log.d(Constants.TAG, "accountName: " + accountName);
|
||||||
// get app settings for this package
|
|
||||||
for (int i = 0; i < callingPackages.length; i++) {
|
|
||||||
String currentPkg = callingPackages[i];
|
|
||||||
|
|
||||||
Uri uri = KeychainContract.ApiAccounts.buildByPackageAndAccountUri(currentPkg, accountName);
|
Uri uri = KeychainContract.ApiAccounts.buildByPackageAndAccountUri(currentPkg, accountName);
|
||||||
|
|
||||||
AccountSettings settings = ProviderHelper.getApiAccountSettings(this, uri);
|
AccountSettings settings = ProviderHelper.getApiAccountSettings(this, uri);
|
||||||
|
|
||||||
if (settings != null) {
|
return settings; // can be null!
|
||||||
return settings;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
protected Intent getCreateAccountIntent(Intent data, String accountName) {
|
||||||
|
String packageName = getCurrentCallingPackage();
|
||||||
|
Log.d(Constants.TAG, "accountName: " + accountName);
|
||||||
|
|
||||||
|
Intent intent = new Intent(getBaseContext(), RemoteServiceActivity.class);
|
||||||
|
intent.setAction(RemoteServiceActivity.ACTION_CREATE_ACCOUNT);
|
||||||
|
intent.putExtra(RemoteServiceActivity.EXTRA_PACKAGE_NAME, packageName);
|
||||||
|
intent.putExtra(RemoteServiceActivity.EXTRA_ACC_NAME, accountName);
|
||||||
|
intent.putExtra(RemoteServiceActivity.EXTRA_DATA, data);
|
||||||
|
|
||||||
|
PendingIntent pi = PendingIntent.getActivity(getBaseContext(),
|
||||||
|
PRIVATE_REQUEST_CODE_REGISTER, intent, 0);
|
||||||
|
|
||||||
|
// return PendingIntent to be executed by client
|
||||||
|
Intent result = new Intent();
|
||||||
|
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED);
|
||||||
|
result.putExtra(OpenPgpApi.RESULT_INTENT, pi);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,8 +45,8 @@ import java.util.ArrayList;
|
|||||||
public class RemoteServiceActivity extends ActionBarActivity {
|
public class RemoteServiceActivity extends ActionBarActivity {
|
||||||
|
|
||||||
public static final String ACTION_REGISTER = Constants.INTENT_PREFIX + "API_ACTIVITY_REGISTER";
|
public static final String ACTION_REGISTER = Constants.INTENT_PREFIX + "API_ACTIVITY_REGISTER";
|
||||||
public static final String ACTION_REGISTER_ACCOUNT = Constants.INTENT_PREFIX
|
public static final String ACTION_CREATE_ACCOUNT = Constants.INTENT_PREFIX
|
||||||
+ "API_ACTIVITY_REGISTER_ACCOUNT";
|
+ "API_ACTIVITY_CREATE_ACCOUNT";
|
||||||
public static final String ACTION_CACHE_PASSPHRASE = Constants.INTENT_PREFIX
|
public static final String ACTION_CACHE_PASSPHRASE = Constants.INTENT_PREFIX
|
||||||
+ "API_ACTIVITY_CACHE_PASSPHRASE";
|
+ "API_ACTIVITY_CACHE_PASSPHRASE";
|
||||||
public static final String ACTION_SELECT_PUB_KEYS = Constants.INTENT_PREFIX
|
public static final String ACTION_SELECT_PUB_KEYS = Constants.INTENT_PREFIX
|
||||||
@ -130,7 +130,7 @@ public class RemoteServiceActivity extends ActionBarActivity {
|
|||||||
|
|
||||||
AppSettings settings = new AppSettings(packageName, packageSignature);
|
AppSettings settings = new AppSettings(packageName, packageSignature);
|
||||||
mAppSettingsFragment.setAppSettings(settings);
|
mAppSettingsFragment.setAppSettings(settings);
|
||||||
} else if (ACTION_REGISTER_ACCOUNT.equals(action)) {
|
} else if (ACTION_CREATE_ACCOUNT.equals(action)) {
|
||||||
final String packageName = extras.getString(EXTRA_PACKAGE_NAME);
|
final String packageName = extras.getString(EXTRA_PACKAGE_NAME);
|
||||||
final String accName = extras.getString(EXTRA_ACC_NAME);
|
final String accName = extras.getString(EXTRA_ACC_NAME);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user