android: Remove special handling of legacy Android versions in native code

Since minSdkVersion has been 21 for a while, we can remove some code
that was necessary for older versions.
This commit is contained in:
Tobias Brunner 2025-03-07 10:10:56 +01:00
parent 523067e6db
commit 77f99df656
4 changed files with 5 additions and 53 deletions

View File

@ -48,17 +48,11 @@ extern jclass *android_charonvpnservice_builder_class;
extern jclass *android_simple_fetcher_class;
/**
* Currently known (supported) SDK versions
* SDK versions for which we need some special handling.
*
* see android.os.Build.VERSION_CODES for definitions
*/
typedef enum {
ANDROID_ICE_CREAM_SANDWICH = 14,
ANDROID_ICE_CREAM_SANDWICH_MR1 = 15,
ANDROID_JELLY_BEAN = 16,
ANDROID_JELLY_BEAN_MR1 = 17,
ANDROID_JELLY_BEAN_MR2 = 18,
ANDROID_LOLLIPOP = 21,
ANDROID_MARSHMALLOW = 23,
} android_sdk_version_t;

View File

@ -435,16 +435,7 @@ METHOD(private_key_t, destroy, void,
JNIEnv *env;
androidjni_attach_thread(&env);
if (android_sdk_version == ANDROID_JELLY_BEAN)
{ /* there is a bug in JB that causes a SIGSEGV if the key object is
* garbage collected so we intentionally leak the reference to it */
DBG1(DBG_LIB, "intentionally leaking private key reference due to "
"a bug in the framework");
}
else
{
(*env)->DeleteGlobalRef(env, this->key);
}
(*env)->DeleteGlobalRef(env, this->key);
(*env)->DeleteGlobalRef(env, this->signature_class);
androidjni_detach_thread();
this->pubkey->destroy(this->pubkey);

View File

@ -792,10 +792,9 @@ static job_requeue_t initiate(private_android_service_t *this)
};
char *type, *remote_id;
if (android_sdk_version >= ANDROID_LOLLIPOP)
{ /* only try once and notify the GUI on Android 5+ where we have a blocking TUN device */
peer.keyingtries = 1;
}
/* only try once and notify the GUI since Android 5+ where we have a
* blocking TUN device */
peer.keyingtries = 1;
ike.remote = this->settings->get_str(this->settings, "connection.server",
NULL);

View File

@ -124,11 +124,6 @@ METHOD(kernel_net_t, get_source_addr, host_t*,
}
charonservice->bypass_socket(charonservice, skt, dst->get_family(dst));
if (android_sdk_version <= ANDROID_JELLY_BEAN_MR2)
{ /* this seems to help avoiding the VIP, unless there is no connectivity
* at all */
charonservice->bypass_socket(charonservice, -1, 0);
}
if (connect(skt, dst->get_sockaddr(dst), addrlen) < 0)
{
/* don't report an error if we are not connected (ENETUNREACH) */
@ -179,28 +174,6 @@ CALLBACK(vip_equals, bool,
return host->ip_equals(host, vip);
}
METHOD(kernel_net_t, get_source_addr_old, host_t*,
private_android_net_t *this, host_t *dest, host_t *src)
{
host_t *host;
/* on older Android versions we might get the virtual IP back because
* the protect() implementation there and connect() don't properly work
* together, on newer releases (using fwmarks) that's not a problem */
host = get_source_addr(this, dest, src);
if (host)
{
this->mutex->lock(this->mutex);
if (this->vips->find_first(this->vips, vip_equals, NULL, host))
{
host->destroy(host);
host = NULL;
}
this->mutex->unlock(this->mutex);
}
return host;
}
METHOD(kernel_net_t, get_nexthop, host_t*,
private_android_net_t *this, host_t *dest, int prefix, host_t *src,
char **iface)
@ -303,11 +276,6 @@ kernel_net_t *kernel_android_net_create()
);
timerclear(&this->next_roam);
if (android_sdk_version <= ANDROID_JELLY_BEAN_MR2)
{
this->public.get_source_addr = _get_source_addr_old;
}
this->mutex->lock(this->mutex);
this->network_manager->add_connectivity_cb(
this->network_manager, (void*)connectivity_cb, this);