forked from Halium/libhybris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'prop-fallback' into xenial_-_edge
- Loading branch information
Showing
11 changed files
with
349 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/* | ||
* Copyright (c) 2018 Jolla Ltd. <[email protected]> | ||
* Copyright (c) 2020 UBports foundation <[email protected]> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -22,12 +23,18 @@ | |
#include <hybris/common/binding.h> | ||
|
||
static void *libcutils = NULL; | ||
static int own_impl = 0; | ||
|
||
// These may point to the libhybris implementation or to the bionic implementation, depending on the linker being used. | ||
static int (*bionic_property_list)(void (*propfn)(const char *key, const char *value, void *cookie), void *cookie) = NULL; | ||
static int (*bionic_property_get)(const char *key, char *value, const char *default_value) = NULL; | ||
static int (*bionic_property_set)(const char *key, const char *value) = NULL; | ||
|
||
// Private implementations as fallback | ||
extern int my_property_list(void (*propfn)(const char *key, const char *value, void *cookie), void *cookie); | ||
extern int my_property_get(const char *key, char *value, const char *default_value); | ||
extern int my_property_set(const char *key, const char *value); | ||
|
||
static void unload_libcutils(void) | ||
{ | ||
if (libcutils) { | ||
|
@@ -43,16 +50,16 @@ static void unload_libcutils(void) | |
|
||
static void ensure_bionic_properties_initialized(void) | ||
{ | ||
if (!libcutils) { | ||
if (!libcutils && !own_impl) { | ||
libcutils = android_dlopen("libcutils.so", RTLD_LAZY); | ||
if (libcutils) { | ||
PROPERTY_DLSYM(property_get); | ||
PROPERTY_DLSYM(property_set); | ||
PROPERTY_DLSYM(property_list); | ||
atexit(unload_libcutils); | ||
} else { | ||
fprintf(stderr, "failed to load bionic libc.so\n"); | ||
abort(); | ||
own_impl = 1; | ||
fprintf(stderr, "failed to load bionic libc.so, falling back own property implementation\n"); | ||
} | ||
} | ||
} | ||
|
@@ -61,20 +68,29 @@ int property_list(void (*propfn)(const char *key, const char *value, void *cooki | |
{ | ||
ensure_bionic_properties_initialized(); | ||
|
||
return bionic_property_list(propfn, cookie); | ||
if (!own_impl) | ||
return bionic_property_list(propfn, cookie); | ||
else | ||
return my_property_list(propfn, cookie); | ||
} | ||
|
||
int property_get(const char *key, char *value, const char *default_value) | ||
{ | ||
ensure_bionic_properties_initialized(); | ||
|
||
return bionic_property_get(key, value, default_value); | ||
if (!own_impl) | ||
return bionic_property_get(key, value, default_value); | ||
else | ||
return my_property_get(key, value, default_value); | ||
} | ||
|
||
int property_set(const char *key, const char *value) | ||
{ | ||
ensure_bionic_properties_initialized(); | ||
|
||
return bionic_property_set(key, value); | ||
if (!own_impl) | ||
return bionic_property_set(key, value); | ||
else | ||
return my_property_set(key, value); | ||
} | ||
|
Oops, something went wrong.