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, null,
0, 0,
0, 0,
0); 0,
Compatibility.pgpStartIntentSenderOptions());
} catch (SendIntentException e) { } catch (SendIntentException e) {
Toast.makeText( Toast.makeText(
getActivity(), getActivity(),
@ -3400,7 +3401,7 @@ public class ConversationFragment extends XmppFragment
try { try {
getActivity() getActivity()
.startIntentSenderForResult( .startIntentSenderForResult(
pendingIntent.getIntentSender(), requestCode, null, 0, 0, 0); pendingIntent.getIntentSender(), requestCode, null, 0, 0, 0, Compatibility.pgpStartIntentSenderOptions());
} catch (final SendIntentException ignored) { } 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.MenuDoubleTabUtil;
import eu.siacs.conversations.ui.util.PendingItem; import eu.siacs.conversations.ui.util.PendingItem;
import eu.siacs.conversations.ui.util.SoftKeyboardUtils; import eu.siacs.conversations.ui.util.SoftKeyboardUtils;
import eu.siacs.conversations.utils.Compatibility;
import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.Resolver; import eu.siacs.conversations.utils.Resolver;
import eu.siacs.conversations.utils.SignupUtils; import eu.siacs.conversations.utils.SignupUtils;
@ -982,7 +983,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
public void userInputRequired(PendingIntent pi, String object) { public void userInputRequired(PendingIntent pi, String object) {
mPendingPresenceTemplate.push(template); mPendingPresenceTemplate.push(template);
try { 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) { } catch (final IntentSender.SendIntentException ignored) {
} }
} }

View file

@ -48,7 +48,6 @@ import android.widget.Toast;
import androidx.annotation.BoolRes; import androidx.annotation.BoolRes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AlertDialog.Builder; import androidx.appcompat.app.AlertDialog.Builder;
@ -57,12 +56,6 @@ import androidx.databinding.DataBindingUtil;
import com.google.common.base.Strings; 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.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.PgpEngine; 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.services.XmppConnectionService.XmppConnectionBinder;
import eu.siacs.conversations.ui.util.MenuDoubleTabUtil; import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
import eu.siacs.conversations.ui.util.PresenceSelector; 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.ui.util.SoftKeyboardUtils;
import eu.siacs.conversations.utils.AccountUtils; import eu.siacs.conversations.utils.AccountUtils;
import eu.siacs.conversations.utils.Compatibility; import eu.siacs.conversations.utils.Compatibility;
import eu.siacs.conversations.utils.ExceptionHelper; import eu.siacs.conversations.utils.ExceptionHelper;
import eu.siacs.conversations.ui.util.SettingsUtils;
import eu.siacs.conversations.utils.SignupUtils; import eu.siacs.conversations.utils.SignupUtils;
import eu.siacs.conversations.utils.ThemeHelper; import eu.siacs.conversations.utils.ThemeHelper;
import eu.siacs.conversations.xmpp.Jid; import eu.siacs.conversations.xmpp.Jid;
import eu.siacs.conversations.xmpp.OnKeyStatusUpdated; import eu.siacs.conversations.xmpp.OnKeyStatusUpdated;
import eu.siacs.conversations.xmpp.OnUpdateBlocklist; 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 abstract class XmppActivity extends ActionBarActivity {
public static final String EXTRA_ACCOUNT = "account"; 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>() { xmppConnectionService.getPgpEngine().generateSignature(intent, account, status, new UiCallback<String>() {
@Override @Override
public void userInputRequired(PendingIntent pi, String signature) { public void userInputRequired(final PendingIntent pi, final String signature) {
try { 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) { } catch (final SendIntentException ignored) {
} }
} }
@ -707,7 +706,7 @@ public abstract class XmppActivity extends ActionBarActivity {
public void userInputRequired(PendingIntent pi, Account object) { public void userInputRequired(PendingIntent pi, Account object) {
try { try {
startIntentSenderForResult(pi.getIntentSender(), 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) { } catch (final SendIntentException ignored) {
} }
} }
@ -881,8 +880,9 @@ public abstract class XmppActivity extends ActionBarActivity {
try { try {
startIntentSenderForResult( startIntentSenderForResult(
pgp.getIntentForKey(keyId).getIntentSender(), 0, null, 0, pgp.getIntentForKey(keyId).getIntentSender(), 0, null, 0,
0, 0); 0, 0, Compatibility.pgpStartIntentSenderOptions());
} catch (Throwable e) { } 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(); 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.XmppActivity;
import eu.siacs.conversations.ui.util.AvatarWorkerTask; import eu.siacs.conversations.ui.util.AvatarWorkerTask;
import eu.siacs.conversations.ui.util.MucDetailsContextMenuHelper; import eu.siacs.conversations.ui.util.MucDetailsContextMenuHelper;
import eu.siacs.conversations.utils.Compatibility;
import eu.siacs.conversations.xmpp.Jid; import eu.siacs.conversations.xmpp.Jid;
public class UserAdapter extends ListAdapter<MucOptions.User, UserAdapter.ViewHolder> implements View.OnCreateContextMenuListener { 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()); PendingIntent intent = pgpEngine.getIntentForKey(user.getPgpKeyId());
if (intent != null) { if (intent != null) {
try { 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) { } 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 static eu.siacs.conversations.services.EventReceiver.EXTRA_NEEDS_FOREGROUND_SERVICE;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.ActivityOptions;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -10,6 +11,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.os.Build; import android.os.Build;
import android.os.Bundle;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceCategory; import android.preference.PreferenceCategory;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@ -20,15 +22,15 @@ import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.core.content.ContextCompat; 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.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.ui.SettingsActivity; import eu.siacs.conversations.ui.SettingsActivity;
import eu.siacs.conversations.ui.SettingsFragment; import eu.siacs.conversations.ui.SettingsFragment;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Compatibility { public class Compatibility {
private static final List<String> UNUSED_SETTINGS_POST_TWENTYSIX = private static final List<String> UNUSED_SETTINGS_POST_TWENTYSIX =
@ -41,7 +43,8 @@ public class Compatibility {
Collections.singletonList("message_notification_settings"); Collections.singletonList("message_notification_settings");
public static boolean hasStoragePermission(final Context context) { 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( || ContextCompat.checkSelfPermission(
context, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) context, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED; == PackageManager.PERMISSION_GRANTED;
@ -177,4 +180,15 @@ public class Compatibility {
return ConnectivityManager.RESTRICT_BACKGROUND_STATUS_DISABLED; 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;
}
}
} }