Skip to content

Commit

Permalink
libmbutil: Place system properties fork in mb namespace
Browse files Browse the repository at this point in the history
There were symbol conflicts previously masked due to
-Wl,--allow-multiple-definition, which is required due to conflicts
between libc.a and libandroid_support.a.

Signed-off-by: Andrew Gunnerson <[email protected]>
  • Loading branch information
chenxiaolong committed Jul 3, 2018
1 parent 5fc1a07 commit 8fb3205
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 178 deletions.
6 changes: 3 additions & 3 deletions libmbutil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ set_source_files_properties(
)

set_source_files_properties(
src/external/system_properties_compat.c
src/external/system_properties_compat.cpp
PROPERTIES
COMPILE_FLAGS
"-Wno-cast-align -Wno-cast-qual -Wno-shorten-64-to-32 -Wno-sign-conversion -Wno-strict-prototypes"
"-Wno-shorten-64-to-32 -Wno-sign-conversion"
)

set(variants)
Expand Down Expand Up @@ -53,7 +53,7 @@ foreach(variant ${variants})
src/time.cpp
src/vibrate.cpp
src/external/system_properties.cpp
src/external/system_properties_compat.c
src/external/system_properties_compat.cpp
src/result/file_op_result.cpp
)

Expand Down
2 changes: 1 addition & 1 deletion libmbutil/external.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
commit: 3c75c11a5cb537bbdf499701e4298cee2e07a604

- files:
- src/external/system_properties_compat.c
- src/external/system_properties_compat.cpp
repo: https://android.googlesource.com/platform/bionic
tag: android-7.1.2_r36
commit: 8011119dffb81326eeecdc2effb3b878d536ff50
53 changes: 27 additions & 26 deletions libmbutil/include/mbutil/external/_system_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@

#include "mbutil/external/system_properties.h"

__BEGIN_DECLS
namespace mb
{

#define MB_ENABLE_COMPAT_PROPERTIES 1

Expand All @@ -63,38 +64,38 @@ __BEGIN_DECLS
** Map the property area from the specified filename. This
** method is for testing only.
*/
int mb__system_property_set_filename(const char *filename);
int __system_property_set_filename(const char *filename);

/*
** Initialize the area to be used to store properties. Can
** only be done by a single process that has write access to
** the property area.
*/
int mb__system_property_area_init();
int __system_property_area_init();

/* Read the global serial number of the system properties
**
** Called to predict if a series of cached mb__system_property_find
** objects will have seen mb__system_property_serial values change.
** Called to predict if a series of cached __system_property_find
** objects will have seen __system_property_serial values change.
** But also aids the converse, as changes in the global serial can
** also be used to predict if a failed mb__system_property_find
** also be used to predict if a failed __system_property_find
** could in-turn now find a new object; thus preventing the
** cycles of effort to poll mb__system_property_find.
** cycles of effort to poll __system_property_find.
**
** Typically called at beginning of a cache cycle to signal if _any_ possible
** changes have occurred since last. If there is, one may check each individual
** mb__system_property_serial to confirm dirty, or mb__system_property_find
** to check if the property now exists. If a call to mb__system_property_add
** or mb__system_property_update has completed between two calls to
** mb__system_property_area_serial then the second call will return a larger
** __system_property_serial to confirm dirty, or __system_property_find
** to check if the property now exists. If a call to __system_property_add
** or __system_property_update has completed between two calls to
** __system_property_area_serial then the second call will return a larger
** value than the first call. Beware of race conditions as changes to the
** properties are not atomic, the main value of this call is to determine
** whether the expensive mb__system_property_find is worth retrying to see if
** whether the expensive __system_property_find is worth retrying to see if
** a property now exists.
**
** Returns the serial number on success, -1 on error.
*/
uint32_t mb__system_property_area_serial();
uint32_t __system_property_area_serial();

/* Add a new system property. Can only be done by a single
** process that has write access to the property area, and
Expand All @@ -104,48 +105,48 @@ uint32_t mb__system_property_area_serial();
**
** Returns 0 on success, -1 if the property area is full.
*/
int mb__system_property_add(const char *name, unsigned int namelen, const char *value, unsigned int valuelen);
int __system_property_add(const char *name, unsigned int namelen, const char *value, unsigned int valuelen);

/* Update the value of a system property returned by
** mb__system_property_find. Can only be done by a single process
** __system_property_find. Can only be done by a single process
** that has write access to the property area, and that process
** must handle sequencing to ensure that only one property is
** updated at a time.
**
** Returns 0 on success, -1 if the parameters are incorrect.
*/
int mb__system_property_update(prop_info *pi, const char *value, unsigned int len);
int __system_property_update(prop_info *pi, const char *value, unsigned int len);

/* Read the serial number of a system property returned by
** mb__system_property_find.
** __system_property_find.
**
** Returns the serial number on success, -1 on error.
*/
uint32_t mb__system_property_serial(const prop_info* pi);
uint32_t __system_property_serial(const prop_info* pi);

/* Initialize the system properties area in read only mode.
* Should be done by all processes that need to read system
* properties.
*
* Returns 0 on success, -1 otherwise.
*/
int mb__system_properties_init();
int __system_properties_init();

/* Deprecated: use mb__system_property_wait instead. */
uint32_t mb__system_property_wait_any(uint32_t old_serial);
/* Deprecated: use __system_property_wait instead. */
uint32_t __system_property_wait_any(uint32_t old_serial);

#if MB_ENABLE_COMPAT_PROPERTIES
/* Compatibility functions to support using an old init with a new libc,
** mostly for the OTA updater binary. These can be deleted once OTAs from
** a pre-K release no longer needed to be supported. */
uint32_t mb__system_property_serial_compat(const prop_info *pi);
const prop_info *mb__system_property_find_compat(const char *name);
int mb__system_property_read_compat(const prop_info *pi, char *name, char *value);
int mb__system_property_foreach_compat(
uint32_t __system_property_serial_compat(const prop_info *pi);
const prop_info *__system_property_find_compat(const char *name);
int __system_property_read_compat(const prop_info *pi, char *name, char *value);
int __system_property_foreach_compat(
void (*propfn)(const prop_info *pi, void *cookie),
void *cookie);
#endif

__END_DECLS
}

#endif
40 changes: 21 additions & 19 deletions libmbutil/include/mbutil/external/system_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
#include <stddef.h>
#include <stdint.h>

__BEGIN_DECLS
struct timespec;

namespace mb
{

typedef struct prop_info prop_info;

Expand All @@ -43,30 +46,30 @@ typedef struct prop_info prop_info;
/*
* Sets system property `key` to `value`, creating the system property if it doesn't already exist.
*/
int mb__system_property_set(const char* key, const char* value) /* __INTRODUCED_IN(12) */;
int __system_property_set(const char* key, const char* value) /* __INTRODUCED_IN(12) */;

/*
* Returns a `prop_info` corresponding system property `name`, or nullptr if it doesn't exist.
* Use mb__system_property_read_callback to query the current value.
* Use __system_property_read_callback to query the current value.
*
* Property lookup is expensive, so it can be useful to cache the result of this function.
*/
const prop_info* mb__system_property_find(const char* name);
const prop_info* __system_property_find(const char* name);

/*
* Calls `callback` with a consistent trio of name, value, and serial number for property `pi`.
*/
void mb__system_property_read_callback(const prop_info *pi,
void __system_property_read_callback(const prop_info *pi,
void (*callback)(void* cookie, const char *name, const char *value, uint32_t serial),
void* cookie) /* __INTRODUCED_IN(26) */;

/*
* Passes a `prop_info` for each system property to the provided
* callback. Use mb__system_property_read_callback() to read the value.
* callback. Use __system_property_read_callback() to read the value.
*
* This method is for inspecting and debugging the property system, and not generally useful.
*/
int mb__system_property_foreach(void (*propfn)(const prop_info* pi, void* cookie), void* cookie)
int __system_property_foreach(void (*propfn)(const prop_info* pi, void* cookie), void* cookie)
/* __INTRODUCED_IN(19) */;

/*
Expand All @@ -81,22 +84,21 @@ int mb__system_property_foreach(void (*propfn)(const prop_info* pi, void* cookie
* Returns true and updates `*new_serial_ptr` on success, or false if the call
* timed out.
*/
struct timespec;
bool mb__system_property_wait(const prop_info* pi,
uint32_t old_serial,
uint32_t* new_serial_ptr,
const struct timespec* relative_timeout)
bool __system_property_wait(const prop_info* pi,
uint32_t old_serial,
uint32_t* new_serial_ptr,
const struct timespec* relative_timeout)
/* __INTRODUCED_IN(26) */;

/* Deprecated. In Android O and above, there's no limit on property name length. */
#define PROP_NAME_MAX 32
/* Deprecated. Use mb__system_property_read_callback instead. */
int mb__system_property_read(const prop_info* pi, char* name, char* value);
/* Deprecated. Use mb__system_property_read_callback instead. */
int mb__system_property_get(const char* name, char* value);
/* Deprecated. Use mb__system_property_foreach instead. */
const prop_info* mb__system_property_find_nth(unsigned n);
/* Deprecated. Use __system_property_read_callback instead. */
int __system_property_read(const prop_info* pi, char* name, char* value);
/* Deprecated. Use __system_property_read_callback instead. */
int __system_property_get(const char* name, char* value);
/* Deprecated. Use __system_property_foreach instead. */
const prop_info* __system_property_find_nth(unsigned n);

__END_DECLS
}

#endif
Loading

0 comments on commit 8fb3205

Please sign in to comment.