allow background activity start for OpenKeyChain intents

This commit is contained in:
Daniel Gultsch 2023-10-28 18:02:20 +02:00
parent ea5ffe92ea
commit 0bbc1193e3
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
5 changed files with 39 additions and 22 deletions

View file

@ -481,7 +481,8 @@ public class ConversationFragment extends XmppFragment
null,
0,
0,
0);
0,
Compatibility.pgpStartIntentSenderOptions());
} catch (SendIntentException e) {
Toast.makeText(
getActivity(),
@ -3400,7 +3401,7 @@ public class ConversationFragment extends XmppFragment
try {
getActivity()
.startIntentSenderForResult(
pendingIntent.getIntentSender(), requestCode, null, 0, 0, 0);
pendingIntent.getIntentSender(), requestCode, null, 0, 0, 0, Compatibility.pgpStartIntentSenderOptions());
} catch (final SendIntentException ignored) {
}
}

View file

@ -66,6 +66,7 @@ import eu.siacs.conversations.ui.util.AvatarWorkerTask;
import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
import eu.siacs.conversations.ui.util.PendingItem;
import eu.siacs.conversations.ui.util.SoftKeyboardUtils;
import eu.siacs.conversations.utils.Compatibility;
import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.Resolver;
import eu.siacs.conversations.utils.SignupUtils;
@ -982,7 +983,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
public void userInputRequired(PendingIntent pi, String object) {
mPendingPresenceTemplate.push(template);
try {
startIntentSenderForResult(pi.getIntentSender(), REQUEST_CHANGE_STATUS, null, 0, 0, 0);
startIntentSenderForResult(pi.getIntentSender(), REQUEST_CHANGE_STATUS, null, 0, 0, 0, Compatibility.pgpStartIntentSenderOptions());
} catch (final IntentSender.SendIntentException ignored) {
}
}

View file

@ -48,7 +48,6 @@ import android.widget.Toast;
import androidx.annotation.BoolRes;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AlertDialog.Builder;
@ -57,12 +56,6 @@ import androidx.databinding.DataBindingUtil;
import com.google.common.base.Strings;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.RejectedExecutionException;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.PgpEngine;
@ -80,17 +73,23 @@ import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder;
import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
import eu.siacs.conversations.ui.util.PresenceSelector;
import eu.siacs.conversations.ui.util.SettingsUtils;
import eu.siacs.conversations.ui.util.SoftKeyboardUtils;
import eu.siacs.conversations.utils.AccountUtils;
import eu.siacs.conversations.utils.Compatibility;
import eu.siacs.conversations.utils.ExceptionHelper;
import eu.siacs.conversations.ui.util.SettingsUtils;
import eu.siacs.conversations.utils.SignupUtils;
import eu.siacs.conversations.utils.ThemeHelper;
import eu.siacs.conversations.xmpp.Jid;
import eu.siacs.conversations.xmpp.OnKeyStatusUpdated;
import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.RejectedExecutionException;
public abstract class XmppActivity extends ActionBarActivity {
public static final String EXTRA_ACCOUNT = "account";
@ -644,9 +643,9 @@ public abstract class XmppActivity extends ActionBarActivity {
xmppConnectionService.getPgpEngine().generateSignature(intent, account, status, new UiCallback<String>() {
@Override
public void userInputRequired(PendingIntent pi, String signature) {
public void userInputRequired(final PendingIntent pi, final String signature) {
try {
startIntentSenderForResult(pi.getIntentSender(), REQUEST_ANNOUNCE_PGP, null, 0, 0, 0);
startIntentSenderForResult(pi.getIntentSender(), REQUEST_ANNOUNCE_PGP, null, 0, 0, 0,Compatibility.pgpStartIntentSenderOptions());
} catch (final SendIntentException ignored) {
}
}
@ -707,7 +706,7 @@ public abstract class XmppActivity extends ActionBarActivity {
public void userInputRequired(PendingIntent pi, Account object) {
try {
startIntentSenderForResult(pi.getIntentSender(),
REQUEST_CHOOSE_PGP_ID, null, 0, 0, 0);
REQUEST_CHOOSE_PGP_ID, null, 0, 0, 0, Compatibility.pgpStartIntentSenderOptions());
} catch (final SendIntentException ignored) {
}
}
@ -881,8 +880,9 @@ public abstract class XmppActivity extends ActionBarActivity {
try {
startIntentSenderForResult(
pgp.getIntentForKey(keyId).getIntentSender(), 0, null, 0,
0, 0);
} catch (Throwable e) {
0, 0, Compatibility.pgpStartIntentSenderOptions());
} catch (final Throwable e) {
Log.d(Config.LOGTAG,"could not launch OpenKeyChain", e);
Toast.makeText(XmppActivity.this, R.string.openpgp_error, Toast.LENGTH_SHORT).show();
}
}

View file

@ -25,6 +25,7 @@ import eu.siacs.conversations.ui.ConferenceDetailsActivity;
import eu.siacs.conversations.ui.XmppActivity;
import eu.siacs.conversations.ui.util.AvatarWorkerTask;
import eu.siacs.conversations.ui.util.MucDetailsContextMenuHelper;
import eu.siacs.conversations.utils.Compatibility;
import eu.siacs.conversations.xmpp.Jid;
public class UserAdapter extends ListAdapter<MucOptions.User, UserAdapter.ViewHolder> implements View.OnCreateContextMenuListener {
@ -104,7 +105,7 @@ public class UserAdapter extends ListAdapter<MucOptions.User, UserAdapter.ViewHo
PendingIntent intent = pgpEngine.getIntentForKey(user.getPgpKeyId());
if (intent != null) {
try {
activity.startIntentSenderForResult(intent.getIntentSender(), 0, null, 0, 0, 0);
activity.startIntentSenderForResult(intent.getIntentSender(), 0, null, 0, 0, 0, Compatibility.pgpStartIntentSenderOptions());
} catch (IntentSender.SendIntentException ignored) {
}

View file

@ -3,6 +3,7 @@ package eu.siacs.conversations.utils;
import static eu.siacs.conversations.services.EventReceiver.EXTRA_NEEDS_FOREGROUND_SERVICE;
import android.annotation.SuppressLint;
import android.app.ActivityOptions;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@ -10,6 +11,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.os.Build;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceManager;
@ -20,15 +22,15 @@ import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.core.content.ContextCompat;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.ui.SettingsActivity;
import eu.siacs.conversations.ui.SettingsFragment;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Compatibility {
private static final List<String> UNUSED_SETTINGS_POST_TWENTYSIX =
@ -41,7 +43,8 @@ public class Compatibility {
Collections.singletonList("message_notification_settings");
public static boolean hasStoragePermission(final Context context) {
return Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
return Build.VERSION.SDK_INT < Build.VERSION_CODES.M
|| Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
|| ContextCompat.checkSelfPermission(
context, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED;
@ -177,4 +180,15 @@ public class Compatibility {
return ConnectivityManager.RESTRICT_BACKGROUND_STATUS_DISABLED;
}
}
public static Bundle pgpStartIntentSenderOptions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
return ActivityOptions.makeBasic()
.setPendingIntentBackgroundActivityStartMode(
ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED)
.toBundle();
} else {
return null;
}
}
}