insert api app when key is selected in SelectSignKeyIdFragment as well
This commit is contained in:
parent
54498ef4c4
commit
22f4eb3e44
|
@ -119,7 +119,7 @@ public class ApiAppDao extends AbstractDao {
|
|||
public void addAllowedKeyIdForApp(String packageName, long allowedKeyId) {
|
||||
InsertAllowedKey statement = new InsertAllowedKey(getWritableDb());
|
||||
statement.bind(packageName, allowedKeyId);
|
||||
statement.execute();
|
||||
statement.executeInsert();
|
||||
|
||||
getDatabaseNotifyManager().notifyApiAppChange(packageName);
|
||||
}
|
||||
|
|
|
@ -137,9 +137,10 @@ public class ApiPendingIntentFactory {
|
|||
}
|
||||
|
||||
public PendingIntent createSelectSignKeyIdLegacyPendingIntent(Intent data, String packageName,
|
||||
String preferredUserId) {
|
||||
byte[] packageSignature, String preferredUserId) {
|
||||
Intent intent = new Intent(mContext, SelectSignKeyIdActivity.class);
|
||||
intent.putExtra(SelectSignKeyIdActivity.EXTRA_PACKAGE_NAME, packageName);
|
||||
intent.putExtra(SelectSignKeyIdActivity.EXTRA_PACKAGE_SIGNATURE, packageSignature);
|
||||
intent.putExtra(SelectSignKeyIdActivity.EXTRA_USER_ID, preferredUserId);
|
||||
|
||||
return createInternal(data, intent);
|
||||
|
|
|
@ -702,10 +702,11 @@ public class OpenPgpService extends Service {
|
|||
return result;
|
||||
} else {
|
||||
String currentPkg = mApiPermissionHelper.getCurrentCallingPackage();
|
||||
byte[] packageSignature = mApiPermissionHelper.getPackageCertificateOrError(currentPkg);
|
||||
String preferredUserId = data.getStringExtra(OpenPgpApi.EXTRA_USER_ID);
|
||||
|
||||
PendingIntent pi = mApiPendingIntentFactory.createSelectSignKeyIdLegacyPendingIntent(
|
||||
data, currentPkg, preferredUserId);
|
||||
data, currentPkg, packageSignature, preferredUserId);
|
||||
|
||||
// return PendingIntent to be executed by client
|
||||
Intent result = new Intent();
|
||||
|
@ -722,13 +723,14 @@ public class OpenPgpService extends Service {
|
|||
|
||||
{ // return PendingIntent to be executed by client
|
||||
String currentPkg = mApiPermissionHelper.getCurrentCallingPackage();
|
||||
byte[] packageSignature = mApiPermissionHelper.getPackageCertificateOrError(currentPkg);
|
||||
String preferredUserId = data.getStringExtra(OpenPgpApi.EXTRA_USER_ID);
|
||||
PendingIntent pi;
|
||||
// the new dialog doesn't really work if we don't have a user id to work with. just show the old...
|
||||
if (TextUtils.isEmpty(preferredUserId)) {
|
||||
pi = mApiPendingIntentFactory.createSelectSignKeyIdLegacyPendingIntent(data, currentPkg, null);
|
||||
pi = mApiPendingIntentFactory.createSelectSignKeyIdLegacyPendingIntent(
|
||||
data, currentPkg, packageSignature, null);
|
||||
} else {
|
||||
byte[] packageSignature = mApiPermissionHelper.getPackageCertificateOrError(currentPkg);
|
||||
boolean showAutocryptHint = data.getBooleanExtra(OpenPgpApi.EXTRA_SHOW_AUTOCRYPT_HINT, false);
|
||||
pi = mApiPendingIntentFactory.createSelectSignKeyIdPendingIntent(
|
||||
data, currentPkg, packageSignature, preferredUserId, showAutocryptHint);
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
|
||||
package org.sufficientlysecure.keychain.remote.ui;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
@ -35,6 +35,7 @@ import timber.log.Timber;
|
|||
public class SelectSignKeyIdActivity extends BaseActivity {
|
||||
|
||||
public static final String EXTRA_PACKAGE_NAME = "package_name";
|
||||
public static final String EXTRA_PACKAGE_SIGNATURE = "package_signature";
|
||||
public static final String EXTRA_USER_ID = OpenPgpApi.EXTRA_USER_ID;
|
||||
public static final String EXTRA_DATA = "data";
|
||||
|
||||
|
@ -70,17 +71,19 @@ public class SelectSignKeyIdActivity extends BaseActivity {
|
|||
|
||||
Intent intent = getIntent();
|
||||
String packageName = intent.getStringExtra(EXTRA_PACKAGE_NAME);
|
||||
byte[] packageSignature = intent.getByteArrayExtra(EXTRA_PACKAGE_SIGNATURE);
|
||||
mPreferredUserId = intent.getStringExtra(EXTRA_USER_ID);
|
||||
mData = intent.getParcelableExtra(EXTRA_DATA);
|
||||
if (packageName == null) {
|
||||
Timber.e("Intent data missing. Should be Uri of app!");
|
||||
finish();
|
||||
} else {
|
||||
startListFragments(savedInstanceState, packageName, mData, mPreferredUserId);
|
||||
startListFragments(savedInstanceState, packageName, packageSignature, mData, mPreferredUserId);
|
||||
}
|
||||
}
|
||||
|
||||
private void startListFragments(Bundle savedInstanceState, String packageName, Intent data, String preferredUserId) {
|
||||
private void startListFragments(Bundle savedInstanceState, String packageName, byte[] packageSignature, Intent data,
|
||||
String preferredUserId) {
|
||||
// However, if we're being restored from a previous state,
|
||||
// then we don't need to do anything and should return or else
|
||||
// we could end up with overlapping fragments.
|
||||
|
@ -90,7 +93,7 @@ public class SelectSignKeyIdActivity extends BaseActivity {
|
|||
|
||||
// Create an instance of the fragments
|
||||
SelectSignKeyIdListFragment listFragment = SelectSignKeyIdListFragment
|
||||
.newInstance(packageName, data, preferredUserId);
|
||||
.newInstance(packageName, packageSignature, data, preferredUserId);
|
||||
// Add the fragment to the 'fragment_container' FrameLayout
|
||||
// NOTE: We use commitAllowingStateLoss() to prevent weird crashes!
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
|
|
|
@ -34,6 +34,7 @@ import android.widget.LinearLayout;
|
|||
import org.openintents.openpgp.util.OpenPgpApi;
|
||||
import org.openintents.openpgp.util.OpenPgpUtils;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.model.ApiApp;
|
||||
import org.sufficientlysecure.keychain.model.SubKey.UnifiedKeyInfo;
|
||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||
import org.sufficientlysecure.keychain.daos.ApiAppDao;
|
||||
|
@ -46,6 +47,7 @@ import org.sufficientlysecure.keychain.ui.keyview.GenericViewModel;
|
|||
|
||||
public class SelectSignKeyIdListFragment extends RecyclerFragment<KeyChoiceAdapter> {
|
||||
private static final String ARG_PACKAGE_NAME = "package_name";
|
||||
private static final String ARG_PACKAGE_SIGNATURE = "package_signature";
|
||||
private static final String ARG_PREF_UID = "pref_uid";
|
||||
public static final String ARG_DATA = "data";
|
||||
|
||||
|
@ -57,12 +59,15 @@ public class SelectSignKeyIdListFragment extends RecyclerFragment<KeyChoiceAdapt
|
|||
private Intent resultIntent;
|
||||
private String prefUid;
|
||||
private String packageName;
|
||||
private byte[] packageSignature;
|
||||
|
||||
public static SelectSignKeyIdListFragment newInstance(String packageName, Intent data, String preferredUserId) {
|
||||
public static SelectSignKeyIdListFragment newInstance(String packageName, byte[] packageSignature,
|
||||
Intent data, String preferredUserId) {
|
||||
SelectSignKeyIdListFragment frag = new SelectSignKeyIdListFragment();
|
||||
Bundle args = new Bundle();
|
||||
|
||||
args.putString(ARG_PACKAGE_NAME, packageName);
|
||||
args.putByteArray(ARG_PACKAGE_SIGNATURE, packageSignature);
|
||||
args.putParcelable(ARG_DATA, data);
|
||||
args.putString(ARG_PREF_UID, preferredUserId);
|
||||
|
||||
|
@ -103,6 +108,7 @@ public class SelectSignKeyIdListFragment extends RecyclerFragment<KeyChoiceAdapt
|
|||
resultIntent = getArguments().getParcelable(ARG_DATA);
|
||||
prefUid = getArguments().getString(ARG_PREF_UID);
|
||||
packageName = getArguments().getString(ARG_PACKAGE_NAME);
|
||||
packageSignature = getArguments().getByteArray(ARG_PACKAGE_SIGNATURE);
|
||||
|
||||
setEmptyText(getString(R.string.list_empty));
|
||||
setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
|
@ -149,6 +155,8 @@ public class SelectSignKeyIdListFragment extends RecyclerFragment<KeyChoiceAdapt
|
|||
}
|
||||
|
||||
private void onSelectKeyItemClicked(UnifiedKeyInfo keyInfo) {
|
||||
ApiApp apiApp = ApiApp.create(packageName, packageSignature);
|
||||
apiAppDao.insertApiApp(apiApp);
|
||||
apiAppDao.addAllowedKeyIdForApp(packageName, keyInfo.master_key_id());
|
||||
resultIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, keyInfo.master_key_id());
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ public class DebugActionsActivity extends Activity {
|
|||
});
|
||||
addButtonToLayout(context, verticalLayout, "Select Signing Key (legacy)").setOnClickListener((v) -> {
|
||||
PendingIntent pendingIntent = pendingIntentFactory.createSelectSignKeyIdLegacyPendingIntent(
|
||||
new Intent(), BuildConfig.APPLICATION_ID, "test@openkeychain.org");
|
||||
new Intent(), BuildConfig.APPLICATION_ID, getPackageSig(), "test@openkeychain.org");
|
||||
startPendingIntent(pendingIntent);
|
||||
});
|
||||
addButtonToLayout(context, verticalLayout, "Select Signing Key").setOnClickListener((v) -> {
|
||||
|
|
Loading…
Reference in a new issue