From d4ab5114a470154a84383c331ae6a47776efa045 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 27 Feb 2024 11:59:47 +0100 Subject: [PATCH] Add BIND_ALLOW_ACTIVITY_STARTS flag to bindService --- .../openpgp/util/OpenPgpServiceConnection.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java b/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java index 61ccbfe..b78af4f 100644 --- a/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java +++ b/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java @@ -20,6 +20,7 @@ import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; +import android.os.Build; import android.os.IBinder; import org.openintents.openpgp.IOpenPgpService2; @@ -99,8 +100,14 @@ public void bindToService() { Intent serviceIntent = new Intent(OpenPgpApi.SERVICE_INTENT_2); // NOTE: setPackage is very important to restrict the intent to this provider only! serviceIntent.setPackage(mProviderPackageName); - boolean connect = mApplicationContext.bindService(serviceIntent, mServiceConnection, - Context.BIND_AUTO_CREATE); + boolean connect; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + connect = mApplicationContext.bindService(serviceIntent, mServiceConnection, + Context.BIND_AUTO_CREATE | Context.BIND_ALLOW_ACTIVITY_STARTS); + } else { + connect = mApplicationContext.bindService(serviceIntent, mServiceConnection, + Context.BIND_AUTO_CREATE); + } if (!connect) { throw new Exception("bindService() returned false!"); }