-
Notifications
You must be signed in to change notification settings - Fork 155
Use android/system/core to provide libcutils, liblp, libsparse #1206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Databean
wants to merge
3
commits into
google:main
Choose a base branch
from
Databean:android_system_core
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package( | ||
default_visibility = ["//visibility:public"], | ||
) | ||
|
||
cc_library( | ||
name = "libcutils", | ||
srcs = [ | ||
"libcutils/android_get_control_env.h", | ||
"libcutils/android_get_control_file.cpp", | ||
"libcutils/canned_fs_config.cpp", | ||
"libcutils/fs_config.cpp", | ||
"libcutils/fs_config.h", | ||
"libcutils/include/cutils/android_get_control_file.h", | ||
"libcutils/include/cutils/sockets.h", | ||
"libcutils/socket_inaddr_any_server_unix.cpp", | ||
"libcutils/socket_local_client_unix.cpp", | ||
"libcutils/socket_local_server_unix.cpp", | ||
"libcutils/socket_local_unix.h", | ||
"libcutils/socket_network_client_unix.cpp", | ||
"libcutils/sockets.cpp", | ||
"libcutils/sockets_unix.cpp", | ||
], | ||
hdrs = glob([ | ||
"libcutils/include/cutils/*.h", | ||
"libcutils/include/private/*.h", | ||
]), | ||
strip_include_prefix = "libcutils/include", | ||
copts = ["-Ilibcutils"], | ||
deps = [ | ||
"@@//android:log_header", | ||
"@@//libbase", | ||
], | ||
) | ||
|
||
cc_library( | ||
name = "liblp", | ||
srcs = [ | ||
"fs_mgr/liblp/builder.cpp", | ||
"fs_mgr/liblp/images.cpp", | ||
"fs_mgr/liblp/images.h", | ||
"fs_mgr/liblp/partition_opener.cpp", | ||
"fs_mgr/liblp/reader.cpp", | ||
"fs_mgr/liblp/reader.h", | ||
"fs_mgr/liblp/super_layout_builder.cpp", | ||
"fs_mgr/liblp/utility.cpp", | ||
"fs_mgr/liblp/writer.cpp", | ||
"fs_mgr/liblp/writer.h", | ||
"fs_mgr/liblp/utility.h", | ||
], | ||
hdrs = [ | ||
"fs_mgr/liblp/include/liblp/builder.h", | ||
"fs_mgr/liblp/include/liblp/liblp.h", | ||
"fs_mgr/liblp/include/liblp/metadata_format.h", | ||
"fs_mgr/liblp/include/liblp/partition_opener.h", | ||
"fs_mgr/liblp/include/liblp/property_fetcher.h", | ||
"fs_mgr/liblp/include/liblp/super_layout_builder.h", | ||
], | ||
copts = [ | ||
"-Ifs_mgr/liblp", | ||
], | ||
includes = [ | ||
"fs_mgr/liblp/include", | ||
], | ||
deps = [ | ||
":libsparse", | ||
"@@//libbase", | ||
"@@//libext4_utils", | ||
], | ||
) | ||
|
||
cc_library( | ||
name = "libsparse", | ||
srcs = [ | ||
"libsparse/backed_block.cpp", | ||
"libsparse/backed_block.h", | ||
"libsparse/defs.h", | ||
"libsparse/output_file.cpp", | ||
"libsparse/output_file.h", | ||
"libsparse/sparse.cpp", | ||
"libsparse/sparse_crc32.cpp", | ||
"libsparse/sparse_crc32.h", | ||
"libsparse/sparse_defs.h", | ||
"libsparse/sparse_err.cpp", | ||
"libsparse/sparse_file.h", | ||
"libsparse/sparse_format.h", | ||
"libsparse/sparse_read.cpp", | ||
], | ||
hdrs = [ | ||
"libsparse/include/sparse/sparse.h", | ||
], | ||
copts = [ | ||
"-Ilibsparse", | ||
"-Wno-vla-cxx-extension", | ||
"-Wno-c99-designator", | ||
], | ||
includes = ["libsparse/include"], | ||
deps = [ | ||
"@@//libbase", | ||
"@zlib", | ||
], | ||
) | ||
|
||
cc_binary( | ||
name = "simg2img", | ||
srcs = ["libsparse/simg2img.cpp"], | ||
deps = [":libsparse"], | ||
) | ||
|
This file contains hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,179 @@ | ||
/* | ||
* Copyright (C) 2016 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <sys/cdefs.h> | ||
|
||
#include <chrono> | ||
#include <limits> | ||
#include <mutex> | ||
#include <optional> | ||
#include <string> | ||
|
||
struct prop_info; | ||
|
||
namespace android { | ||
namespace base { | ||
|
||
// Returns the current value of the system property `key`, | ||
// or `default_value` if the property is empty or doesn't exist. | ||
std::string GetProperty(const std::string& key, const std::string& default_value); | ||
|
||
// Returns true if the system property `key` has the value "1", "y", "yes", "on", or "true", | ||
// false for "0", "n", "no", "off", or "false", or `default_value` otherwise. | ||
bool GetBoolProperty(const std::string& key, bool default_value); | ||
|
||
// Returns the signed integer corresponding to the system property `key`. | ||
// If the property is empty, doesn't exist, doesn't have an integer value, or is outside | ||
// the optional bounds, returns `default_value`. | ||
template <typename T> T GetIntProperty(const std::string& key, | ||
T default_value, | ||
T min = std::numeric_limits<T>::min(), | ||
T max = std::numeric_limits<T>::max()); | ||
|
||
// Returns the unsigned integer corresponding to the system property `key`. | ||
// If the property is empty, doesn't exist, doesn't have an integer value, or is outside | ||
// the optional bound, returns `default_value`. | ||
template <typename T> T GetUintProperty(const std::string& key, | ||
T default_value, | ||
T max = std::numeric_limits<T>::max()); | ||
|
||
// Sets the system property `key` to `value`. | ||
bool SetProperty(const std::string& key, const std::string& value); | ||
|
||
// Waits for the system property `key` to have the value `expected_value`. | ||
// Times out after `relative_timeout`. | ||
// Returns true on success, false on timeout. | ||
#if defined(__BIONIC__) | ||
bool WaitForProperty(const std::string& key, const std::string& expected_value, | ||
std::chrono::milliseconds relative_timeout = std::chrono::milliseconds::max()); | ||
#endif | ||
|
||
// Waits for the system property `key` to be created. | ||
// Times out after `relative_timeout`. | ||
// Returns true on success, false on timeout. | ||
#if defined(__BIONIC__) | ||
bool WaitForPropertyCreation(const std::string& key, std::chrono::milliseconds relative_timeout = | ||
std::chrono::milliseconds::max()); | ||
#endif | ||
|
||
#if defined(__BIONIC__) && __cplusplus >= 201703L | ||
// Cached system property lookup. For code that needs to read the same property multiple times, | ||
// this class helps optimize those lookups. | ||
class CachedProperty { | ||
public: | ||
explicit CachedProperty(std::string property_name); | ||
|
||
// Kept for ABI compatibility. | ||
explicit CachedProperty(const char* property_name); | ||
|
||
// Returns the current value of the underlying system property as cheaply as possible. | ||
// The returned pointer is valid until the next call to Get. Because most callers are going | ||
// to want to parse the string returned here and cache that as well, this function performs | ||
// no locking, and is completely thread unsafe. It is the caller's responsibility to provide a | ||
// lock for thread-safety. | ||
// | ||
// Note: *changed can be set to true even if the contents of the property remain the same. | ||
const char* Get(bool* changed = nullptr); | ||
|
||
// Waits for the property to be changed and then reads its value. | ||
// Times out returning nullptr, after `relative_timeout` | ||
// | ||
// Note: this can return the same value multiple times in a row if the property was set to the | ||
// same value or if multiple changes happened before the current thread was resumed. | ||
const char* WaitForChange( | ||
std::chrono::milliseconds relative_timeout = std::chrono::milliseconds::max()); | ||
|
||
private: | ||
std::string property_name_; | ||
const prop_info* prop_info_; | ||
std::optional<uint32_t> cached_area_serial_; | ||
std::optional<uint32_t> cached_property_serial_; | ||
char cached_value_[92]; | ||
bool is_read_only_; | ||
const char* read_only_property_; | ||
}; | ||
|
||
// Helper class for passing the output of CachedProperty to a parser function, and then caching | ||
// that as well. | ||
template <typename Parser> | ||
class CachedParsedProperty { | ||
public: | ||
using value_type = std::remove_reference_t<std::invoke_result_t<Parser, const char*>>; | ||
|
||
CachedParsedProperty(std::string property_name, Parser parser) | ||
: cached_property_(std::move(property_name)), parser_(std::move(parser)) {} | ||
|
||
// Returns the parsed value. | ||
// This function is internally-synchronized, so use from multiple threads is safe (but ordering | ||
// of course cannot be guaranteed without external synchronization). | ||
value_type Get(bool* changed = nullptr) { | ||
std::lock_guard<std::mutex> lock(mutex_); | ||
bool local_changed = false; | ||
const char* value = cached_property_.Get(&local_changed); | ||
if (!cached_result_ || local_changed) { | ||
cached_result_ = parser_(value); | ||
} | ||
|
||
if (changed) *changed = local_changed; | ||
return *cached_result_; | ||
} | ||
|
||
private: | ||
std::mutex mutex_; | ||
CachedProperty cached_property_; | ||
std::optional<value_type> cached_result_; | ||
|
||
Parser parser_; | ||
}; | ||
|
||
// Helper for CachedParsedProperty that uses android::base::ParseBool. | ||
class CachedBoolProperty { | ||
public: | ||
explicit CachedBoolProperty(std::string property_name); | ||
|
||
// Returns the parsed bool, or std::nullopt if it wasn't set or couldn't be parsed. | ||
std::optional<bool> GetOptional(); | ||
|
||
// Returns the parsed bool, or default_value if it wasn't set or couldn't be parsed. | ||
bool Get(bool default_value); | ||
|
||
private: | ||
CachedParsedProperty<std::optional<bool> (*)(const char*)> cached_parsed_property_; | ||
}; | ||
|
||
#endif | ||
|
||
static inline int HwTimeoutMultiplier() { | ||
return android::base::GetIntProperty("ro.hw_timeout_multiplier", 1); | ||
} | ||
|
||
} // namespace base | ||
} // namespace android | ||
|
||
#if !defined(__BIONIC__) | ||
/** Implementation detail. */ | ||
extern "C" int __system_property_set(const char*, const char*); | ||
/** Implementation detail. */ | ||
extern "C" int __system_property_get(const char*, char*); | ||
/** Implementation detail. */ | ||
extern "C" const prop_info* __system_property_find(const char*); | ||
/** Implementation detail. */ | ||
extern "C" void __system_property_read_callback(const prop_info*, | ||
void (*)(void*, const char*, const char*, uint32_t), | ||
void*); | ||
#endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we use libbase from android too? If you do that first you won't need to fix this copy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
libbase is going to be more trouble since the internal version doesn't include the logging parts in favor of using abseil logging. Either we'll have to get creative in copybara or we'll have to migrate to abseil logging in our code here on GitHub.