incremental_delivery.patch 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. Submodule src/incremental_delivery contains modified content
  2. diff --git a/src/incremental_delivery/sysprop/IncrementalProperties.sysprop.cpp b/src/incremental_delivery/sysprop/IncrementalProperties.sysprop.cpp
  3. new file mode 100644
  4. index 0000000..dfe0671
  5. --- /dev/null
  6. +++ b/src/incremental_delivery/sysprop/IncrementalProperties.sysprop.cpp
  7. @@ -0,0 +1,217 @@
  8. +// Generated by the sysprop generator. DO NOT EDIT!
  9. +
  10. +#include <IncrementalProperties.sysprop.h>
  11. +#include <strings.h>
  12. +
  13. +#include <cctype>
  14. +#include <cerrno>
  15. +#include <cstdio>
  16. +#include <cstring>
  17. +#include <limits>
  18. +#include <utility>
  19. +#ifdef __BIONIC__
  20. +#include <sys/system_properties.h>
  21. +[[maybe_unused]] static bool SetProp(const char* key, const char* value) {
  22. + return __system_property_set(key, value) == 0;
  23. +}
  24. +#else
  25. +#include <android-base/properties.h>
  26. +[[maybe_unused]] static bool SetProp(const char* key, const char* value) {
  27. + android::base::SetProperty(key, value);
  28. + return true;
  29. +}
  30. +#endif
  31. +
  32. +#include <android-base/parseint.h>
  33. +#include <log/log.h>
  34. +
  35. +namespace {
  36. +
  37. +using namespace android::sysprop::IncrementalProperties;
  38. +
  39. +template <typename T>
  40. +T DoParse(const char* str);
  41. +
  42. +template <typename T>
  43. +constexpr bool is_vector = false;
  44. +
  45. +template <typename T>
  46. +constexpr bool is_vector<std::vector<T>> = true;
  47. +
  48. +template <>
  49. +[[maybe_unused]] std::optional<bool> DoParse(const char* str) {
  50. + static constexpr const char* kYes[] = {"1", "true"};
  51. + static constexpr const char* kNo[] = {"0", "false"};
  52. +
  53. + for (const char* yes : kYes) {
  54. + if (strcasecmp(yes, str) == 0) return std::make_optional(true);
  55. + }
  56. +
  57. + for (const char* no : kNo) {
  58. + if (strcasecmp(no, str) == 0) return std::make_optional(false);
  59. + }
  60. +
  61. + return std::nullopt;
  62. +}
  63. +
  64. +template <>
  65. +[[maybe_unused]] std::optional<std::int32_t> DoParse(const char* str) {
  66. + std::int32_t ret;
  67. + return android::base::ParseInt(str, &ret) ? std::make_optional(ret) : std::nullopt;
  68. +}
  69. +
  70. +template <>
  71. +[[maybe_unused]] std::optional<std::uint32_t> DoParse(const char* str) {
  72. + std::uint32_t ret;
  73. + return android::base::ParseUint(str, &ret) ? std::make_optional(ret) : std::nullopt;
  74. +}
  75. +
  76. +template <>
  77. +[[maybe_unused]] std::optional<std::int64_t> DoParse(const char* str) {
  78. + std::int64_t ret;
  79. + return android::base::ParseInt(str, &ret) ? std::make_optional(ret) : std::nullopt;
  80. +}
  81. +
  82. +template <>
  83. +[[maybe_unused]] std::optional<std::uint64_t> DoParse(const char* str) {
  84. + std::uint64_t ret;
  85. + return android::base::ParseUint(str, &ret) ? std::make_optional(ret) : std::nullopt;
  86. +}
  87. +
  88. +template <>
  89. +[[maybe_unused]] std::optional<double> DoParse(const char* str) {
  90. + int old_errno = errno;
  91. + errno = 0;
  92. + char* end;
  93. + double ret = std::strtod(str, &end);
  94. + if (errno != 0) {
  95. + return std::nullopt;
  96. + }
  97. + if (str == end || *end != '\0') {
  98. + errno = EINVAL;
  99. + return std::nullopt;
  100. + }
  101. + errno = old_errno;
  102. + return std::make_optional(ret);
  103. +}
  104. +
  105. +template <>
  106. +[[maybe_unused]] std::optional<std::string> DoParse(const char* str) {
  107. + return *str == '\0' ? std::nullopt : std::make_optional(str);
  108. +}
  109. +
  110. +template <typename Vec>
  111. +[[maybe_unused]] Vec DoParseList(const char* str) {
  112. + Vec ret;
  113. + if (*str == '\0') return ret;
  114. + const char* p = str;
  115. + for (;;) {
  116. + const char* r = p;
  117. + std::string value;
  118. + while (*r != ',') {
  119. + if (*r == '\\') ++r;
  120. + if (*r == '\0') break;
  121. + value += *r++;
  122. + }
  123. + ret.emplace_back(DoParse<typename Vec::value_type>(value.c_str()));
  124. + if (*r == '\0') break;
  125. + p = r + 1;
  126. + }
  127. + return ret;
  128. +}
  129. +
  130. +template <typename T>
  131. +inline T TryParse(const char* str) {
  132. + if constexpr (is_vector<T>) {
  133. + return DoParseList<T>(str);
  134. + } else {
  135. + return DoParse<T>(str);
  136. + }
  137. +}
  138. +
  139. +[[maybe_unused]] std::string FormatValue(const std::optional<std::int32_t>& value) {
  140. + return value ? std::to_string(*value) : "";
  141. +}
  142. +
  143. +[[maybe_unused]] std::string FormatValue(const std::optional<std::uint32_t>& value) {
  144. + return value ? std::to_string(*value) : "";
  145. +}
  146. +
  147. +[[maybe_unused]] std::string FormatValue(const std::optional<std::int64_t>& value) {
  148. + return value ? std::to_string(*value) : "";
  149. +}
  150. +
  151. +[[maybe_unused]] std::string FormatValue(const std::optional<std::uint64_t>& value) {
  152. + return value ? std::to_string(*value) : "";
  153. +}
  154. +
  155. +[[maybe_unused]] std::string FormatValue(const std::optional<double>& value) {
  156. + if (!value) return "";
  157. + char buf[1024];
  158. + std::sprintf(buf, "%.*g", std::numeric_limits<double>::max_digits10, *value);
  159. + return buf;
  160. +}
  161. +
  162. +[[maybe_unused]] std::string FormatValue(const std::optional<bool>& value) {
  163. + return value ? (*value ? "true" : "false") : "";
  164. +}
  165. +
  166. +template <typename T>
  167. +[[maybe_unused]] std::string FormatValue(const std::vector<T>& value) {
  168. + if (value.empty()) return "";
  169. +
  170. + std::string ret;
  171. + bool first = true;
  172. +
  173. + for (auto&& element : value) {
  174. + if (!first)
  175. + ret += ',';
  176. + else
  177. + first = false;
  178. + if constexpr (std::is_same_v<T, std::optional<std::string>>) {
  179. + if (element) {
  180. + for (char c : *element) {
  181. + if (c == '\\' || c == ',') ret += '\\';
  182. + ret += c;
  183. + }
  184. + }
  185. + } else {
  186. + ret += FormatValue(element);
  187. + }
  188. + }
  189. +
  190. + return ret;
  191. +}
  192. +
  193. +template <typename T>
  194. +T GetProp(const char* key, const char* legacy = nullptr) {
  195. + std::string value;
  196. +#ifdef __BIONIC__
  197. + auto pi = __system_property_find(key);
  198. + if (pi != nullptr) {
  199. + __system_property_read_callback(
  200. + pi,
  201. + [](void* cookie, const char*, const char* value, std::uint32_t) {
  202. + *static_cast<std::string*>(cookie) = value;
  203. + },
  204. + &value);
  205. + }
  206. +#else
  207. + value = android::base::GetProperty(key, "");
  208. +#endif
  209. + if (value.empty() && legacy) {
  210. + ALOGV("prop %s doesn't exist; fallback to legacy prop %s", key, legacy);
  211. + return GetProp<T>(legacy);
  212. + }
  213. + return TryParse<T>(value.c_str());
  214. +}
  215. +
  216. +} // namespace
  217. +
  218. +namespace android::sysprop::IncrementalProperties {
  219. +
  220. +std::optional<std::string> enable() {
  221. + return GetProp<std::optional<std::string>>("ro.incremental.enable");
  222. +}
  223. +
  224. +} // namespace android::sysprop::IncrementalProperties
  225. \ No newline at end of file
  226. diff --git a/src/incremental_delivery/sysprop/include/IncrementalProperties.sysprop.h b/src/incremental_delivery/sysprop/include/IncrementalProperties.sysprop.h
  227. new file mode 100644
  228. index 0000000..19e2fea
  229. --- /dev/null
  230. +++ b/src/incremental_delivery/sysprop/include/IncrementalProperties.sysprop.h
  231. @@ -0,0 +1,14 @@
  232. +// Generated by the sysprop generator. DO NOT EDIT!
  233. +
  234. +#pragma once
  235. +
  236. +#include <cstdint>
  237. +#include <optional>
  238. +#include <string>
  239. +#include <vector>
  240. +
  241. +namespace android::sysprop::IncrementalProperties {
  242. +
  243. +std::optional<std::string> enable();
  244. +
  245. +} // namespace android::sysprop::IncrementalProperties
  246. \ No newline at end of file