arc_features_parser.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_COMPONENTS_ARC_ARC_FEATURES_PARSER_H_
  5. #define ASH_COMPONENTS_ARC_ARC_FEATURES_PARSER_H_
  6. #include <map>
  7. #include <string>
  8. #include <vector>
  9. #include "base/callback_forward.h"
  10. #include "base/strings/string_piece.h"
  11. #include "third_party/abseil-cpp/absl/types/optional.h"
  12. namespace arc {
  13. // This struct contains an ARC available feature map, unavailable feature set
  14. // and ARC build property map.
  15. struct ArcFeatures {
  16. // Key is the feature name. Value is the feature version.
  17. using FeatureVersionMapping = std::map<std::string, int>;
  18. // Each item in the vector is the feature name.
  19. using FeatureList = std::vector<std::string>;
  20. // Key is the property key, such as "ro.build.version.sdk". Value is the
  21. // corresponding property value.
  22. using BuildPropsMapping = std::map<std::string, std::string>;
  23. ArcFeatures();
  24. ArcFeatures(const ArcFeatures&) = delete;
  25. ArcFeatures& operator=(const ArcFeatures&) = delete;
  26. ArcFeatures(ArcFeatures&& other);
  27. ArcFeatures& operator=(ArcFeatures&& other);
  28. ~ArcFeatures();
  29. // This map contains all ARC system available features. For each feature, it
  30. // has the name and version. Unavailable features have been filtered out from
  31. // this map.
  32. FeatureVersionMapping feature_map;
  33. // This list contains all ARC unavailable feature names.
  34. FeatureList unavailable_features;
  35. // This map contains all ARC build properties.
  36. BuildPropsMapping build_props;
  37. std::string play_store_version;
  38. };
  39. // Parses JSON files for Android system available features and build properties.
  40. //
  41. // A feature JSON file looks like this:
  42. // {
  43. // "features": [
  44. // {
  45. // "name": "android.hardware.location",
  46. // "version: 2
  47. // },
  48. // {
  49. // "name": "android.hardware.location.network",
  50. // "version": 0
  51. // }
  52. // ],
  53. // "unavailable_features": [
  54. // "android.hardware.usb.accessory",
  55. // "android.software.live_tv"
  56. // ],
  57. // "properties": {
  58. // "ro.product.cpu.abilist": "x86_64,x86,armeabi-v7a,armeabi",
  59. // "ro.build.version.sdk": "25"
  60. // },
  61. // "play_store_version": "81010860"
  62. // }
  63. class ArcFeaturesParser {
  64. public:
  65. ArcFeaturesParser(const ArcFeaturesParser&) = delete;
  66. ArcFeaturesParser& operator=(const ArcFeaturesParser&) = delete;
  67. // Get ARC system available features.
  68. static void GetArcFeatures(
  69. base::OnceCallback<void(absl::optional<ArcFeatures>)> callback);
  70. // Given an input feature JSON, return ARC features. This method is for
  71. // testing only.
  72. static absl::optional<ArcFeatures> ParseFeaturesJsonForTesting(
  73. base::StringPiece input_json);
  74. // Overrides the ArcFeatures returned by GetArcFeatures, for testing only.
  75. // Does not take ownership of |getter|, it must be alive when GetArcFeatures
  76. // is called.
  77. static void SetArcFeaturesGetterForTesting(
  78. base::RepeatingCallback<absl::optional<ArcFeatures>()>* getter);
  79. };
  80. } // namespace arc
  81. #endif // ASH_COMPONENTS_ARC_ARC_FEATURES_PARSER_H_