4 // key names for properties we use
6 extern const char* key;
7 extern const char* ref;
8 extern const char* props;
9 extern const char* is_default;
13 * Class to store data on the unencrypted folder of a device.
14 * Note that the folder must exist before this class is constructed.
15 * All names must be valid single level (no '/') file or directory names
16 * Data is organized hierarchically so we can get a child folder
18 class UnencryptedProperties
21 // Get path of folder. Must create before using any properties
22 // This is to allow proper setting of SELinux policy
23 static std::string GetPath(const char* device);
25 // Opens properties folder on named device.
26 // If folder does not exist, OK will return false, all
27 // getters will return default properties and setters will fail.
28 UnencryptedProperties(const char* device);
30 // Get named object. Return default if object does not exist or error.
31 template<typename t> t Get(const char* name, t default_value = t()) const;
33 // Set named object. Return true if success, false otherwise
34 template<typename t> bool Set(const char* name, t const& value);
36 // Get child properties
37 UnencryptedProperties GetChild(const char* name) const;
39 // Remove named object
40 bool Remove(const char* name);
46 UnencryptedProperties();
51 template<typename t> t UnencryptedProperties::Get(const char* name,
52 t default_value) const
54 if (!OK()) return default_value;
55 t value = default_value;
56 std::ifstream(folder_ + "/" + name) >> value;
60 template<typename t> bool UnencryptedProperties::Set(const char* name,
63 if (!OK()) return false;
64 std::ofstream o(folder_ + "/" + name);
69 // Specialized getters/setters for strings
70 template<> std::string UnencryptedProperties::Get(const char* name,
71 std::string default_value) const;
73 template<> bool UnencryptedProperties::Set(const char* name,
74 std::string const& value);